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
Copy matching Pixels
Show Recordset's Current Record
Copy Text - Non Editable Fields & Shockwave
Set Properties of a Flash Sprite
A Simple Back Button
DM XTreme Transitions
27 Sum Game-Game Fields
Send to Top
Components for multimedia applications developers
Mudbox
 

 

 

Behavior Drag & Drop

Added on 6/10/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: GerryOrkin

Drag adn Drop behavior

property TargetSprite -- target sprite for the dragged sprite
property startPos -- starting poition of the dragged sprite

property correctspringBack
--  does the dragged sprite spring back to startpos
--  when released on target? (T/F)

property incorrectspringBack
--  does the dragged sprite spring back to startpos
--  when released off  target? (T/F)

property incorrectvanish

--  does the dragged sprite vanish when released off target? (T/F)

property correctvanish

--  does the dragged sprite vanish when released on target? (T/F)

property IncorrectCommand -- name of the handler to run if sprite dropped on target
property correctCommand -- name of the handler to run if sprite dropped off target

-- end property declaration

on mousedown me
  
  -- get start point of dragged sprite
  set startpos = the loc of sprite (the spritenum of me)
  
  -- move the sprite with the mouse
  repeat while the stilldown = true
    set the loc of sprite (the spritenum of me) = point(the mouseh, the mousev)
    updatestage
  end repeat
  
end

on mouseup me
  -- check to see if the MOUSE is inside the target sprite
  -- when released
  if inside(point(the mouseh, the mousev), the rect of sprite (the targetSprite of me)) then
    
    -- run the handler specified for a correct drop
    do the correctCommand of me
    
    -- if the dragged sprite should vanish then do that
    if the correctvanish of me = 1 then
      -- send the dragged sprite off screen
      set the loc of sprite the spritenum of me = point(1000,1000)
      exit
    end if
    -- sets the dragged sprite back to starting position
    if the correctspringback of me  = 1 then
      set the loc of sprite (the spritenum of me) = startpos
    end if
  else
    -- it was dropped off the target sprite
    
    do the incorrectCommand of me
    -- if the dragged sprite should vanish then do that
    if the incorrectvanish of me = 1 then
      -- send the dragged sprite off screen
      set the loc of sprite the spritenum of me = point(1000,1000)
      exit
    end if
    -- sets the dragged sprite back to starting position
    if the incorrectspringback of me  = 1 then
      set the loc of sprite (the spritenum of me) = startpos
    end if
    
  end if
  
end

on getBehaviorDescription
  return¬
"Creates sprites that can be dropped on any other [user specified] sprite. You can define the target sprite, "&& RETURN &¬
"whether the dragged sprite snaps back to it"s start position, and handlers to run if the drop was on or off target."
  
end


on getPropertyDescriptionList
  
  if voidp(TargetSprite) then set TargetSprite = 1
  
  set p_list = [#TargetSprite: [ #default:TargetSprite,#format:#integer, #comment:"Target Sprite Number", #range:[#min:1,#Max:120]],¬
  #incorrectspringBack:[#default:1,#format:#boolean,#comment:"Spring back when incorrect?"],¬
  #correctspringBack:[#default:0,#format:#boolean,#comment:"Spring back when correct?"],¬
  #incorrectvanish:[#default:0,#format:#boolean,#comment:"Vanish when dropped off the target?"],¬
  #correctvanish:[#default:1,#format:#boolean,#comment:"Vanish when dropped on the target?"],¬
#correctCommand:[#format:#string,#comment:"The handler to run if dropped off the target",#default:"beep" ],¬
#IncorrectCommand:[#format:#string,#comment:"The handler to run if dropped on the target",#default:"beep 2" ]]
  return p_list  
end

 


Contact

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

Send e-mail