Mega Code Archive

 
Categories / Flash ActionScript / TextField
 

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(  );       }     }   } }