2006/04/20 | EventDispatcher的三种使用方法,推荐使用第三种~
类别(网摘) | 评论(0) | 阅读(156) | 发表于 06: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);
}

0

评论Comments

日志分类
首页[28]
flash[3]
javascript[3]
C#[1]
feeling[5]
网摘[16]