topical media & game development

talk show tell print

animation-ch02-Reparenting2.ax

animation-ch02-Reparenting2.ax [swf] [flash] flex


  package {
          import flash.display.Sprite;
          import flash.events.MouseEvent;
          
          public class @ax-animation-ch02-Reparenting2 extends Sprite {
                  private var parent1:animation_ch02_ParentBox;
                  private var parent2:animation_ch02_ParentBox;
                  private var ball:Sprite;
  
                  public function @ax-animation-ch02-Reparenting2() {
                          init();
                  }
                  private function init():void {
                          parent1 = new animation_ch02_ParentBox();
                          addChild(parent1);
                          parent1.x = 60;
                          parent1.y = 60;
                          
                          parent2 = new animation_ch02_ParentBox();
                          addChild(parent2);
                          parent2.x = 170;
                          parent2.y = 60;
                          
                          ball = new Sprite();
                          parent1.addChild(ball);
                          ball.graphics.beginFill(0xff0000);
                          ball.graphics.drawCircle(0, 0, 40);
                          ball.addEventListener(MouseEvent.CLICK, onBallClick);
                  }
                  
                  public function onBallClick(event:MouseEvent):void
                  {
                          parent2.addChild(ball);
                  }
          }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.