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
Rotate Image Algorithm - Imaging Lingo
Making Multiple Animated Buttons
Director Publications
simComportIOCP Xtra
Set ImageEnabled Property of a Flash Sprite
Internet Explorer 5 - PC
Set Static Property of a Flash sprite
Get Keyboard Delay and Speed
Scroll Up/Down
VBScript Xtra / ActiveCompanionSet
 

 

 

Behavior Drag and Droop

Added on 2/6/2001

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: usertron

Put this behaivour on the sprite you want to drag, and on the sprite you want it to snap to. You specify the distance it snaps from in pixels.

-- drag and droop behaivour v1.0 2001 Patrick Hammond, use this at your leasure, if you have any bugs or comments
-- or improvements (regarding this behaivour) you can send me an electronic message at usertron@ihug.co.nz

global gSnapped
property spritenum, pDropRange, pMagnetic, pOriginalLoc


on mouseUp me -- you have dropped the sprite
  gSnapped = 0 -- this is a global flag, set to 1 if the dragged sprite is SNAPPED!
  x = sprite(spritenum).loch -- horizontal dropzone
  y = sprite(spritenum).locv -- vertical dropzone
  sendAllSprites (#areYouNear, x, y, spritenum, pDropRange, pOriginalLoc) -- check to see if anyone is near
  if gSnapped = 0 then sprite(spriteNum).loc = pOriginalLoc -- if no-one is, put me back!
end

on mouseDown me
  pOriginalLoc = sprite(SpriteNum).loc -- record the original position
end

on areYouNear me ,x, y, spriteNumber, SnapRange, SendBack
  
  if spriteNumber = spritenum then exit -- to avoid dropping it on my own head!!
  
  if abs(sprite(spriteNum).loch - x) < SnapRange and abs(sprite(spriteNum).locv - y) < SnapRange  then -- if i am near someone
    if pMagnetic = 1 then -- check to see if they are sticky!
      sprite(spritenumber).loc = sprite(spritenum).loc -- if they are, stick me to their loc
      gSnapped = 1 -- and set the snapped flag
    end if
  end if
  
end

on getBehaviorDescription me
  return("Put this behaivour on the sprite you want to drag, and on the sprite you want it to snap to."&& RETURN &
"You specify the distance it snaps from, and to define a sprite "snappable" use magnetic = true")
end

on getPropertyDescriptionList me
  vPDList = [:]
  setaProp vPDList, #pDropRange, [#comment: "Snap Range (pixels)",
    #format: #integer, #default: 30,
    #range: [#min: 0, #max: 100]]
  setaProp vPDList, #pMagnetic, [#comment: "Magnetic?",
    #format: #boolean, #default: 1]
  return vPDList
end getPropertyDescriptionList

 


Contact

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

Send e-mail