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
Director Online
Wait for a cuepoint
FileFlex
Writing text to the user's drive
An Unofficial Brief History of Director
Show Me Movies
Go Loop
aougu.com
Set Properties of a Flash Sprite
Bubble Sort Algorithm (for Strings)
 

 

 

Behavior Graphic Drag on top

Added on 6/10/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: JohnDowdell

Behavior to swap two sprites during a drag, so that the sprite you"re dragging appears on top of other sprites with this behavior. Nothing really tricky here... the sendAllSprites call will return all sprite channels with this behavior, and so only the last, topmost sprite value will be retained.

property spriteNum, switchedSprite, dragging, offset

on mouseDown me
  set offset to the clickLoc - the loc of sprite spriteNum
  set switchedSprite to sendAllSprites(#GetTopmostSpriteWithDragOnTopBehavior)
  SwapSprites me
  set dragging to TRUE
end

on exitFrame me
  if dragging then
    set the loc of sprite switchedSprite to point(the mouseH, the mouseV) - offset  
    if the mouseUp then
      SwapSprites me  
      set dragging to FALSE
    end if
  end if
end

--  Find the sprite in the uppermost channel with this behavior.
--  Calledby mouseDown handler.
--  Note the weird name... this avoids potential problems from
--  broadcasting a more common name that another behavior might share.
on GetTopMostSpriteWithDragOnTopBehavior me
  return spriteNum
end

--  Routine to change member and loc properties of
--  the clicked sprite and the topmost sprite.
--  Called by mouseDown handler.
on SwapSprites me
  set origMember to the member of sprite spriteNum
  set origLoc to the loc of sprite spriteNum
  set the member of sprite spriteNum to the member of sprite switchedSprite
  set the loc of sprite spriteNum to the loc of sprite switchedSprite
  set the member of sprite switchedSprite to origMember
  set the loc of sprite switchedSprite to origLoc
  if switchedSprite <> spriteNum then
    set the trails of sprite spriteNum to NOT the trails of sprite spriteNum
  end if    
end

on getBehaviorDescription me
  set line1 to "   When you apply this behavior to multiple sprites, then clicking on any of them will move it to the top of the group and you"ll be able to drag it around. " & RETURN
  set line2 to "   The sprites should likely be of the same type if you"ll be doing other things in the meantime, because we"re swapping channels... "
  set line3 to "if you"re sending "movieTime" commands to a video sprite and all of a sudden it"s a bitmap sprite, then things can get weird." & RETURN
  set line4 to "   The topmost sprite of the group has a "trails" effect applied to it temporarily so it appears to stay on top of other stationary sprites. "
  set line5 to "If you drag above this topmost sprite with another then you might see parts of it be erased, but all will pop back to normal when you release the dragged sprite." & RETURN
  set line6 to "   If you wish the dragged sprite to appear above all other elements in the scene, then just put a sprite in the topmost channel and give it this behavior."
  return line1 & line2 & line3 & line4 & line5 & line6
end

 


Contact

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

Send e-mail