Posted By

adamcoulombe on 02/26/10


Tagged

actionscript send back movieclip as3 arrange Front backward forward


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

adrianparr
davidino1978
zoo
tspitzr
dubogii
carlokohan


Bring to Front / Send to Back / Bring Forward / Send Backwards (Movieclip Arrange functions for AS3)


 / Published in: ActionScript 3
 

URL: http://www.adamcoulombe.info/lab/as3/Arrange.html

DEMO: http://www.adamcoulombe.info/lab/as3/Arrange.html FLA: http://www.adamcoulombe.info/lab/as3/Arrange.fla

Some prototype functions that give you easy Bring to Front / Send to Back / Bring Forward / Send Backwards functionality in Flash AS3

  1. MovieClip.prototype.bringToFront = function():void {
  2. this.parent.setChildIndex(this, this.parent.numChildren-1);
  3. }
  4. MovieClip.prototype.sendToBack = function():void {
  5. this.parent.setChildIndex(this, 0);
  6. }
  7. MovieClip.prototype.bringForward = function():void{
  8. var currentDepth = this.parent.getChildIndex(this);
  9. if(currentDepth<this.parent.numChildren-1){
  10. this.parent.setChildIndex(this, currentDepth+1);
  11. }
  12. }
  13. MovieClip.prototype.sendBackward = function():void{
  14. var currentDepth = this.parent.getChildIndex(this);
  15. if(currentDepth>0){
  16. this.parent.setChildIndex(this, currentDepth-1);
  17. }
  18. }
  19. /*
  20. blue.addEventListener(MouseEvent.MOUSE_UP, clicked);
  21. green.addEventListener(MouseEvent.MOUSE_UP, clicked);
  22. orange.addEventListener(MouseEvent.MOUSE_UP, clicked);
  23.  
  24. function clicked(e:MouseEvent){
  25. e.target.sendBackward();
  26. //you also could say...
  27. // e.target.sendBackward();
  28. // e.target.bringForward();
  29. // e.target.sendToBack();
  30. // e.target.bringToFront();
  31. }
  32. */

Report this snippet  

You need to login to post a comment.