Depth test : Sprite « Development « Flash / Flex / ActionScript






Depth test

 
package {

     import flash.display.BlendMode;
     import flash.display.Sprite;
     
     [SWF(width=550, height=400)]
     
     public class Main extends Sprite {
     
          public function Main() {
               var square:Square = new Square();
               addChild(square);
               square.x = 10;
               square.y = 10;

               var square2:Square = new Square();
               addChild(square2);
               square2.x = 43;
               square2.y = 66;

               var square3:Square = new Square();
               addChild(square3);
               square3.x = 93;
               square3.y = 31;

               trace("square: " + getChildIndex(square));
               trace("square2: " + getChildIndex(square2));
               trace("square3: " + getChildIndex(square3));
               
               setChildIndex(square, numChildren-1);
               
               trace("square: " + getChildIndex(square));
               trace("square2: " + getChildIndex(square2));
               trace("square3: " + getChildIndex(square3));
               
               swapChildren(square2, square3);
               swapChildrenAt(0, 2);
               
               trace("square: " + getChildIndex(square));
               trace("square2: " + getChildIndex(square2));
               trace("square3: " + getChildIndex(square3));
               
               square3.blendMode = BlendMode.INVERT;
          }
     
     }
     
}
class Square extends flash.display.Sprite {

     public function Square() {
          graphics.lineStyle(5);
          graphics.beginFill(0xFF);
          graphics.drawRect(0, 0, 100, 100);
          graphics.endFill();
     }

} 

        








Related examples in the same category

1.Add TextField to Sprite
2.Adding an Item to the Display List
3.addChild( ) method doesn't guarantee that a display object is added to the display list.
4.Removing an Item from the Display List
5.Moving Objects Forward and Backward
6.Change child index
7.Manipulating Objects in Containers Collectively
8.Applies a black color transformation to group, causing all children to be colored solid black
9.Containment Events
10.Using the buttonMode of the Sprite
11.Using the hitArea
12.Using hitTestPoint
13.Swapping the Depths of Children
14.Reparenting Display Objects
15.Advanced Masks
16.Masks
17.Building an FLV Playback Application