Util for managing DisplayObject\'s depths


/ Published in: ActionScript 3
Save to your folder(s)

the code is self-explanary


Copy this code and paste it in your HTML
  1. package game.utils{
  2.  
  3. import flash.display.DisplayObject;
  4.  
  5. /*
  6. burnandbass[at]gmail
  7. util for easy managing depths / z-index in stack of a displayObject
  8. Only works within display object's parent list
  9. */
  10.  
  11. public class DisplayUtil {
  12.  
  13. public function DisplayUtil() {
  14. trace("use with static methods only!");
  15. }
  16.  
  17. //sets the Display Object of the top of the stack
  18. public static function sendFront(_do:DisplayObject):void {
  19. _do.parent.setChildIndex(_do,_do.parent.numChildren - 1);
  20. }
  21.  
  22. //sends @_do below @child
  23. public static function sendBelow(_do:DisplayObject, child:DisplayObject):void {
  24. _do.parent.setChildIndex(_do, _do.parent.getChildIndex(child))
  25. }
  26.  
  27. //sets @_do above @child
  28. public static function sendAbove(_do:DisplayObject, child:DisplayObject):void {
  29. _do.parent.setChildIndex(_do, _do.parent.getChildIndex(child));
  30. _do.parent.swapChildren(_do, child);
  31. }
  32.  
  33. //sets @_do at the back of the display list stack
  34. public static function sendBack(_do:DisplayObject):void {
  35. _do.parent.setChildIndex(_do,0);
  36. }
  37.  
  38. }//end
  39. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.