home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
3D World 110
/
3DW_110.iso
/
mac
/
Menu
/
Scenes
/
home.dir
/
00069_Script_Draggable
< prev
next >
Wrap
Text File
|
2008-09-12
|
4KB
|
133 lines
-- Draggable
-- Click and drag sprite to new location
-- 16 Nov DP - incorporated JN fix for compatibility with Draw Connector
-- v1 - 7 October 1998 by Darrel Plant
-- Modified 1 February, 1999 by A.M. Kelsey
-- 7 January 2000 Added isOkToAttach J.Powers
on getBehaviorDescription me
return \
"DRAGGABLE" & RETURN & RETURN & \
"Makes sprite respond to clicking and dragging the mouse button, similar to setting the draggable property of the sprite. " & \
"Sprite movement may constrained to the stage area." & RETURN & RETURN & \
"PERMITTED MEMBER TYPES:" & RETURN & \
"Graphic members" & RETURN & RETURN & \
"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 & \
"PARAMETERS:" & RETURN & \
"* Constrain to stage?"
end getBehaviorDescription
on getBehaviorTooltip me
return \
"Makes a sprite draggable. " & \
"The sprite will move along with the cursor while the mouse button is held down."
end getBehaviorTooltip
-- PROPERTIES --
property pSprite -- sprite object
property pLocOffset -- offset of click from sprite loc
property pActive -- activity flag
-- author-defined properties
property pConstrained -- constrain to stage flag
-- EVENT HANDLERS --
on beginSprite me
-- determine sprite object reference
pSprite = sprite (me.spriteNum)
vMember = pSprite.member
case vMember.type of
#animGIF, #flash, #QuickTimeMedia, #digitalvideo, #vectorShape:
if vMember.directtostage then
alert "Sprite" && pSprite.spriteNum & \
": Direct To Stage media may cause" && \
"playback problems with the 'Moveable Sprite' behavior."
end if
end case
-- set activity flag
pActive = FALSE
end beginSprite
on mouseUp me
-- turn off activity flag when mouse is released
mDrag FALSE
end mouseUp
on mouseDown me
-- turn on activity flag when mouse is clicked
mDrag TRUE
end mouseUp
on prepareFrame me
-- if mouse has somehow moved off of sprite and been released
-- turn off activity flag
if the mouseUp then mDrag FALSE
-- if active, move sprite to follow cursor
if pActive then
mDragSprite me
end if
end prepareFrame
-- CUSTOM HANDLERS --
on mDrag vActive
-- set activity flag
pActive = vActive
-- find distance from sprite loc to mouse click
pLocOffset = pSprite.loc - the mouseLoc
-- inform other behaviors of current state
sendAllSprites (#Active_Sprite, the currentSpriteNum * pActive)
end mDrag
on mDragSprite
-- move sprite to cursor location offset by difference between
-- original click and sprite loc
pSprite.loc = the mouseLoc + pLocOffset
if pConstrained then
vLeftDiff = pSprite.rect.left
if vLeftDiff < 0 then
pSprite.locH = pSprite.locH - vLeftDiff
end if
vRightDiff = pSprite.rect.right - the stage.sourcerect.width
if vRightDiff > 0 then
pSprite.locH = pSprite.locH - vRightDiff
end if
vTopDiff = pSprite.rect.top
if vTopDiff < 0 then
pSprite.locV = pSprite.locV - vTopDiff
end if
vBottomDiff = pSprite.rect.bottom - the stage.sourcerect.height
if vBottomDiff > 0 then
pSprite.locV = pSprite.locV - vBottomDiff
end if
end if
end mDragSprite
-- INTER-BEHAVIOR COMMUNICATION
on Forwarded_mouseDown me
-- turn on activity flag when mouse click is initially
-- intercepted by another behavior and forwarded
if not pActive then
mDrag TRUE
end if
return the currentSpriteNum
end Forwarded_mouseDown
-- AUTHOR-DEFINED PARAMETERS --
on isOKToAttach (me, aSpriteType, aSpriteNum)
return aSpriteType = #Graphic
end
on getPropertyDescriptionList
vPDList = [:]
setaProp vPDList, #pConstrained, [#comment: "Constrain to stage", \
#format: #boolean, #default: TRUE]
return vPDList
end getPropertyDescriptionList