Animating a TextField horizontally to x-coordinate 300, timer version : Animation « TextField « Flash / Flex / ActionScript






Animating a TextField horizontally to x-coordinate 300, timer version

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

  public class Main extends Sprite {
    private var t:TextField = new TextField(  );
    private var timer:Timer;

    public function Main(  ) {
      t.text          = "Hello";
      t.autoSize      = TextFieldAutoSize.LEFT;
      addChild(t);

      timer = new Timer(50, 0);
      timer.addEventListener(TimerEvent.TIMER, moveTextRight);
      timer.start(  );
    }

    public function moveTextRight (e:TimerEvent):void {
      if (t.x <= 300) {
        t.x += 10;
        if (t.x > 300) {
          t.x = 300;
        }
        e.updateAfterEvent(  );  // Update the screen following this function
      } else {
        timer.stop(  );
      }
    }
  }
}

        








Related examples in the same category

1.To eliminate unnecessary function calls, we unregister moveTextRight( ) for Event.ENTER_FRAME events.
2.Animating a TextField horizontally to x-coordinate 300
3.Frame Rate's Effect on Event.ENTER_FRAME Animations
4.Timer event