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






Animating a TextField horizontally to x-coordinate 300

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

  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.To eliminate unnecessary function calls, we unregister moveTextRight( ) for Event.ENTER_FRAME events.
2.Frame Rate's Effect on Event.ENTER_FRAME Animations
3.Animating a TextField horizontally to x-coordinate 300, timer version
4.Timer event