Basic AS 3 event system for AS 2
Having to jump on some Actionscript 2 projects … put this together to help me feel more at home
http://specialrelativity.org/blogAssets/AS2EventSystem.zip
Here is some code showing it being used …
import com.avila.events.EventDispatcher;
import com.avila.events.Event;
import com.avila.utils.ArrayUtil;
/**
* The Main class is used as the document class for the application.
*
* @langversion 2.0
* @playerversion Flash 8
*
* @author Michael Avila
*/
class Main extends EventDispatcher
{
private var name:String = 'michael';
/**
* Creates a new instance of Main
*/
public function Main()
{
var event:Event = new Event( Event.COMPLETE );
addEventListener( Event.COMPLETE, this, complete );
dispatchEvent( event );
}
public function complete( event:Event ):Void
{
trace( event );
trace( name );
}
/**
* The class Main is the document class for the application, the register method
* is used to set Main as the document class. Once it has been set, the constructor method
* for the class Main is invoked.
*
* @param MovieClip should be passed _root timeline of a .swf file
*/
public static function register( document:MovieClip ):Void
{
document.__proto__ = Main.prototype
Function(Main).apply( document, null );
}
}
-M