Docunext


Flash AS3 Example with addEventListener

November 30th, 2009

Here is an example of Flash ActionScript 3 with addEventListener:

Test.hx

package;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.Lib;
class Test extends MovieClip {
    private var s:MovieClip;
    private var z:MovieClip;
    private var eventDispatcher:EventDispatcher;
    private var dir:Int;
    public static function main() {
        new Test();
    }
    public function new(){
        super();
        trace("New");
        dir = 1;
         eventDispatcher = new EventDispatcher ();
         var tf = new flash.text.TextField();
         tf.text = "Hello World !";
         // add it to the display list
         s = new MovieClip();
         s.addChild(tf);
         Lib.current.addChild(s);
         s.y = 40;
         Lib.current.addEventListener (Event.ENTER_FRAME, mover);
    }
    function mover(event:Event):Void {
        if (s.x == 100) {
            dir = -1;
        }
        if (s.x == 1) {
            dir = 1;
        }
        s.x = s.x + dir;
        s.scaleX = s.scaleX + dir/10;
        s.scaleY = s.scaleY + dir/10;
    }
}

compile.hxml

-main Test
-swf-version 9
-swf test.swf
Yearly Indexes: 2003 2004 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020 2022