Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Director 8 and Lingo Bible
Drag and Switch
Radians to degrees, degrees to radians
MultimediaHelp
Wait for Cue Point GTF
Billenium Transitions Xtra v1.1
Vim Scripts for Lingo
Build Environment
Tracking save attempts
Flash Sprite -- Simple Controller [Play, Pause, Rewind]
 

 

 

Behavior Move a line from field to field

Added on 4/4/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: Thomas (website)

This behavior added to a field member allows the user to drag a line from this field to the selected field. Added to two fields it can be used to drag and drop a line from one field to another and back. The behavior uses a field to show what is being dragged, you can set this field up as you wish.

property pWhichLine

property pLineMember
property pLineSpriteNum

property pMyMember
property pMySpriteNum

property pToMember
property pToSpriteNum



on beginSprite me
  
  -- Set constant properties
  pMySpriteNum = the spriteNum of me
  pMyMember = member(pMySpriteNum)
  
  
  -- Find the sprite that has the Line Member
  repeat with x = 1 to  120
    if (sprite(x).member = pLineMember) then
      pLineSpriteNum = x
      exit repeat
    end if
  end repeat
  
  
  -- Find the sprite that has the To-Field Member
  repeat with x = 1 to  120
    if (sprite(x).member = pToMember) then
      pToSpriteNum = x
      exit repeat
    end if
  end repeat
  
  
  -- Puppet this sprite
  puppetSprite pLineSpriteNum, TRUE
  sprite(pLineSpriteNum).visible = FALSE
end



on mouseDown me
  
  -- What line was pressed?
  pWhichLine = the mouseLine
  
  -- Set the text of the item member to the text of the line pressed
  pLineMember.text = pMyMember.line[pWhichLine]
  
  -- If the text is not empty go
  if pLineMember.text <> "" then
    
    -- Show the sprite
    sprite(pLineSpriteNum).visible = TRUE
    
    -- Drag the sprite
    repeat while the mouseDown
      sprite(pLineSpriteNum).loc = the mouseLoc + point(-20,1)
      updateStage
    end repeat
  end if
end



on mouseUp me
  
  -- If the sprite is dragged inside the To-Field
  if inside(the mouseLoc, sprite(pToSpriteNum).rect) = TRUE then
    
    -- Set the variables for the from-field
    varText = pMyMember.text
    varLines = the number of lines of varText
    
    -- Delete the line from the from-field
    repeat with x = 1 to varLines
      if x = pWhichLine then
        nothing
      else
        varNewText = varNewText & varText.line[x] & RETURN
      end if
    end repeat
    
    
    -- Set the variables for the to-field
    varToText = pToMember.text
    varToLines = the number of lines of varToText
    y = 1
    varToNewText = ""
    repeat with x = 1 to varToLines
      if x = the mouseLine then
        varToNewText = varToNewText & pLineMember.text & RETURN
      else
        -- If the line is empty don't insert it - the last line is always empty
        if varToText.line[y] = "" then
          nothing
        else
          varToNewText = varToNewText & varToText.line[y] & RETURN
          y = y + 1
        end if
      end if
    end repeat
    
    
    -- Update both text fields
    pMyMember.text = varNewText
    pToMember.text = varToNewText
  else
    -- beep
  end if
  
  
  
  
  -- If the sprite is dragged to another position within the same field
  if inside(the mouseLoc, sprite(pMySpriteNum).rect) = TRUE then
    
    -- If it is not the same line - go
    if the mouseLine <> pWhichLine then
      -- Set variables
      varText = pMyMember.text
      varLines = the number of lines of varText
      
      -- Delete the line from the text
      repeat with x = 1 to varLines
        if x = pWhichLine then
          nothing
        else
          varNewText = varNewText & varText.line[x] & RETURN
        end if
      end repeat
      
      
      -- Insert the line in its new position
      -- Set variables first
      y = 1
      varText = ""
      repeat with x = 1 to varLines
        if x = the mouseLine then
          varText = varText & pLineMember.text & RETURN
        else
          -- If the line is empty don't insert it - the last line is always empty
          if varNewText.line[y] = "" then
            nothing
          else
            varText = varText & varNewText.line[y] & RETURN
            y = y + 1
          end if
        end if
      end repeat
      
      -- Update text field
      pMyMember.text = varText
    end if
  else
    -- beep
  end if
  
  
  -- Hide the sprite
  sprite(pLineSpriteNum).visible = FALSE
end



on getPropertyDescriptionList
  if the currentSpriteNum = 0 then exit
  
  --  pLineMemberName = "fldItem"
  --  pToMemberName = "fldList2"
  
  
  list = [:]
  addProp list, #pLineMember, [#comment:"Which field member should be used to drag a line?",#format:#field, #default:""]
  addProp list, #pToMember, [#comment:"Which field member should recieve a line?",#format:#field, #default:""]
  
  return list
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail