EventDispatcher的三种使用方法,推荐使用第三种~

      网摘 2006-4-20 6:27

摘自: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);
}

标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}