home *** CD-ROM | disk | FTP | other *** search
/ 3D World 110 / 3DW_110.iso / mac / Menu / Scenes / home.dir / 00069_Script_Draggable < prev    next >
Text File  |  2008-09-12  |  4KB  |  133 lines

  1. -- Draggable
  2. -- Click and drag sprite to new location
  3. -- 16 Nov DP - incorporated JN fix for compatibility with Draw Connector
  4. -- v1 - 7 October 1998 by Darrel Plant
  5. -- Modified 1 February, 1999 by A.M. Kelsey
  6. -- 7 January 2000 Added isOkToAttach J.Powers
  7.  
  8. on getBehaviorDescription me
  9.   return \
  10.     "DRAGGABLE" & RETURN & RETURN & \
  11.     "Makes sprite respond to clicking and dragging the mouse button, similar to setting the draggable property of the sprite. " & \
  12.     "Sprite movement may constrained to the stage area." & RETURN & RETURN & \
  13.     "PERMITTED MEMBER TYPES:" & RETURN & \
  14.     "Graphic members" & RETURN & RETURN & \
  15.     "If using with digital video or other sprites in which Direct to Stage is an option, disable Direct to Stage for best results." & RETURN & RETURN & \
  16.     "PARAMETERS:" & RETURN & \
  17.     "* Constrain to stage?"
  18. end getBehaviorDescription
  19.  
  20. on getBehaviorTooltip me
  21.   return \
  22.     "Makes a sprite draggable. " & \
  23.     "The sprite will move along with the cursor while the mouse button is held down."
  24. end getBehaviorTooltip
  25.  
  26. -- PROPERTIES --
  27.  
  28. property pSprite               -- sprite object
  29. property pLocOffset            -- offset of click from sprite loc
  30. property pActive               -- activity flag
  31. -- author-defined properties
  32. property pConstrained          -- constrain to stage flag
  33.  
  34. -- EVENT HANDLERS --
  35.  
  36. on beginSprite me
  37.   -- determine sprite object reference
  38.   pSprite = sprite (me.spriteNum)
  39.   vMember = pSprite.member
  40.   case vMember.type of
  41.     #animGIF, #flash, #QuickTimeMedia, #digitalvideo, #vectorShape:
  42.       if vMember.directtostage then
  43.         alert "Sprite" && pSprite.spriteNum & \
  44.           ": Direct To Stage media may cause" && \
  45.           "playback problems with the 'Moveable Sprite' behavior."
  46.       end if
  47.   end case
  48.   -- set activity flag
  49.   pActive = FALSE
  50. end beginSprite
  51.  
  52. on mouseUp me
  53.   -- turn off activity flag when mouse is released
  54.   mDrag FALSE
  55. end mouseUp
  56.  
  57. on mouseDown me
  58.   -- turn on activity flag when mouse is clicked
  59.   mDrag TRUE
  60. end mouseUp
  61.  
  62. on prepareFrame me
  63.   -- if mouse has somehow moved off of sprite and been released
  64.   -- turn off activity flag
  65.   if the mouseUp then mDrag FALSE
  66.   -- if active, move sprite to follow cursor
  67.   if pActive then
  68.     mDragSprite me
  69.   end if
  70. end prepareFrame
  71.  
  72.  
  73. -- CUSTOM HANDLERS --
  74.  
  75. on mDrag vActive
  76.   -- set activity flag
  77.   pActive = vActive
  78.   -- find distance from sprite loc to mouse click
  79.   pLocOffset = pSprite.loc - the mouseLoc
  80.   -- inform other behaviors of current state
  81.   sendAllSprites (#Active_Sprite, the currentSpriteNum * pActive)
  82. end mDrag
  83.  
  84. on mDragSprite
  85.   -- move sprite to cursor location offset by difference between
  86.   -- original click and sprite loc
  87.   pSprite.loc = the mouseLoc + pLocOffset
  88.   if pConstrained then
  89.     vLeftDiff = pSprite.rect.left
  90.     if vLeftDiff < 0 then
  91.       pSprite.locH = pSprite.locH - vLeftDiff
  92.     end if
  93.     vRightDiff = pSprite.rect.right - the stage.sourcerect.width
  94.     if vRightDiff > 0 then
  95.       pSprite.locH = pSprite.locH - vRightDiff
  96.     end if
  97.     vTopDiff = pSprite.rect.top
  98.     if vTopDiff < 0 then
  99.       pSprite.locV = pSprite.locV - vTopDiff
  100.     end if
  101.     vBottomDiff = pSprite.rect.bottom - the stage.sourcerect.height
  102.     if vBottomDiff > 0 then
  103.       pSprite.locV = pSprite.locV - vBottomDiff
  104.     end if
  105.   end if
  106. end mDragSprite
  107.  
  108.  
  109. -- INTER-BEHAVIOR COMMUNICATION
  110.  
  111. on Forwarded_mouseDown me
  112.   -- turn on activity flag when mouse click is initially
  113.   -- intercepted by another behavior and forwarded
  114.   if not pActive then
  115.     mDrag TRUE
  116.   end if
  117.   return the currentSpriteNum
  118. end Forwarded_mouseDown
  119.  
  120.  
  121. -- AUTHOR-DEFINED PARAMETERS --
  122.  
  123. on isOKToAttach (me, aSpriteType, aSpriteNum)
  124.   return aSpriteType = #Graphic
  125. end
  126.  
  127. on getPropertyDescriptionList
  128.   vPDList = [:]
  129.   setaProp vPDList, #pConstrained, [#comment: "Constrain to stage", \
  130.     #format: #boolean, #default: TRUE]
  131.   return vPDList
  132. end getPropertyDescriptionList
  133.