rotateChildren( ), applies the generalized code from Example 20-4. It randomly rotates all the descendants of a specified container (not just the children). : Rectangle : Graphics Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Graphics » Rectangle »

 

rotateChildren( ), applies the generalized code from Example 20-4. It randomly rotates all the descendants of a specified container (not just the children).


 

package {
  import flash.display.*;
  import flash.events.*;

  public class RotatingRectangles extends Sprite {
    public function RotatingRectangles (  ) {
      var rects:Array = new Array(  );
      for (var i:int 0; i < 20; i++) {
        rects[inew Shape(  );
        rects[i].graphics.lineStyle(1);
        rects[i].graphics.beginFill(Math.floor(Math.random(  )*0xFFFFFF)1);
        rects[i].graphics.drawRect(0010050);
        rects[i].x = Math.floor(Math.random(  )*500);
        rects[i].y = Math.floor(Math.random(  )*400);
        addChild(rects[i]);
      }

      stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
    }

    private function mouseDownListener (e:Event):void {
      for (var i:int=0; i < numChildren; i++) {
        getChildAt(i).rotation = Math.floor(Math.random(  )*360);
      }
    }

    public function rotateChildren (container:DisplayObjectContainer):void {
      for (var i:int 0; i < container.numChildren; i++) {
        var thisChild:DisplayObject = container.getChildAt(i);
        if (thisChild is DisplayObjectContainer) {
          rotateChildren(DisplayObjectContainer(thisChild));
        else {
          thisChild.rotation =  Math.floor(Math.random(  )*360);
        }
      }
    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Graphics
» Rectangle