topical media & game development

talk show tell print

animation-ch14-OneSegment.ax

animation-ch14-OneSegment.ax [swf] [flash] flex


  package {
          import flash.display.Sprite;
          import flash.display.StageAlign;
          import flash.display.StageScaleMode;
          import flash.events.Event;
  
          public class @ax-animation-ch14-OneSegment extends Sprite
          {
                  private var segment0:animation_ch14_Segment;
                  
                  public function @ax-animation-ch14-OneSegment()
                  {
                          init();
                  }
                  
                  private function init():void
                  {
                          stage.align = StageAlign.TOP_LEFT;
                          stage.scaleMode = StageScaleMode.NO_SCALE;
                          segment0 = new animation_ch14_Segment(100, 20);
                          addChild(segment0);
                          segment0.x = stage.stageWidth / 2;
                          segment0.y = stage.stageHeight / 2;
                          
                          addEventListener(Event.ENTER_FRAME, onEnterFrame);
                  }
                  
                  private function onEnterFrame(event:Event):void
                  {
                          var dx:Number = mouseX - segment0.x;
                          var dy:Number = mouseY - segment0.y;
                          var angle:Number = Math.atan2(dy, dx);
                          segment0.rotation = angle * 180 / Math.PI;
                  }
          }
  }
  


(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.