摘自:http://www.darronschall.com/weblog/archives/000100.cfm
1。Using a static initializer in the class
private static var EventDispatcher_mixin =
EventDispatcher.initialize(MyClass.prototype);
2。Using the constructor to initialize the instance as an event source:
// in the constructor
EventDispatcher.initialize(this);
3。Using composition:
// in class body
private var eventSrc:Object
// in constructor
EventDispatcher.initialize(eventSrc);
// methods:
public function registerView(view) {
eventSrc.addEventListener("change", view);
// more...
}
public function removeView(view) {
eventSrc.removeEventListener("change", view);
// more...
}
private function doSomething() {
var eventObj:Object = new Object();
eventObj.target=this;
eventObj.type = "change";
eventSrc.dispatchEvent(eventObj);
}
回复Comments
作者:
{commentrecontent}