To eliminate unnecessary function calls, we unregister moveTextRight( ) for Event.ENTER_FRAME events. : Animation « TextField « Flash / Flex / ActionScript






To eliminate unnecessary function calls, we unregister moveTextRight( ) for Event.ENTER_FRAME events.

 

package{
    import flash.display.*;
    import flash.text.*;
    import flash.events.*;
    public class Main extends Sprite {
      private var t:TextField = new TextField(  );
    
      public function Main (  ) {
        t.text          = "Hello";
        t.autoSize      = TextFieldAutoSize.LEFT;
        addChild(t);
    
        addEventListener(Event.ENTER_FRAME, moveTextRight);
      }
    
      public function moveTextRight (e:Event):void {
          if (t.x <= 300) {
            t.x += 10;
            if (t.x > 300) {
              t.x = 300;
            }
          } else {
            removeEventListener(Event.ENTER_FRAME, moveTextRight);
          }
    
      }
    }
}

        








Related examples in the same category

1.Animating a TextField horizontally to x-coordinate 300
2.Frame Rate's Effect on Event.ENTER_FRAME Animations
3.Animating a TextField horizontally to x-coordinate 300, timer version
4.Timer event