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
Projector debugger
Create Install
Get Font List without using xtras!
example the filmloop
Help Studio 2000
Text Shifting
Clipboard Xtra
FlushEventsXtra
Yes/No Dialog Box
Cursor Trails
 

 

 

Behavior Sprite Drag - Confine to stage

Added on 10/14/1999

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

Rating:

Author: MediaMacros (website)

This behavior allows you to drag a sprite around the stage but confine it to the stage boundries.

--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know.  :-)

property spriteNum, clickOffset

on mouseDown me
  clickOffset = sprite(spriteNum).loc - the mouseLoc
  stageWidth = the stageRight- the stageLeft
  stageHeight = the stageBottom - the stageTop
  leftAdjust = sprite(spriteNum).locH - sprite(spriteNum).left
  rightAdjust = sprite(spriteNum).locH - sprite(spriteNum).right
  topAdjust = sprite(spriteNum).locV - sprite(spriteNum).top
  bottomAdjust = sprite(spriteNum).locV - sprite(spriteNum).bottom
  repeat while the stillDown
    newLoc = the mouseLoc + clickOffset
    if newLoc.locH > stageWidth + rightAdjust then
      newLoc.locH = stageWidth + rightAdjust
    else if newLoc.locH < 0 + leftAdjust then
      newLoc.locH = 0 + leftAdjust
    end if
    if newLoc.locV > stageHeight + bottomAdjust then
      newLoc.locv = stageHeight + bottomAdjust
    else if newLoc.locV < 0 + topAdjust then
      newLoc.locV = 0 + topAdjust
    end if
    sprite(spriteNum).loc = newLoc
    updateStage
  end repeat
end

on getBehaviorDescription me
  return "Drop this on a sprite to make it draggable but constrained to the limites of the stage."
end

 


Contact

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

Send e-mail