?? sampleinheriteventdispatcher.as
字號:
package org.kingda.book.event
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
public class SampleInheritEventDispatcher extends Sprite
{
public function SampleInheritEventDispatcher() {
//生成一個KingdaSampleDispatcher的實例
var dispatcher:KingdaSampleDispatcher = new KingdaSampleDispatcher();
//標準的實現
dispatcher.addEventListener(KingdaSampleDispatcher.ACTION, actionHandler);
dispatcher.doSomething();
//可以用直接字符串標識事件類型,但推薦使用靜態加const的字符串
dispatcher.addEventListener("KingdaPlaySC", anotherHandler);
//直接用new Event生成一個新的事件對象,該對象的事件類型為"KingdaPlaySC"
dispatcher.dispatchEvent(new Event("KingdaPlaySC"));
//輸出:
//action的偵聽器: [Event type="action" bubbles=false cancelable=false eventPhase=2]
//KingdaPlaySC的偵聽器: [Event type="KingdaPlaySC" bubbles=false cancelable=false eventPhase=2]
}
private function actionHandler(event:Event):void {
trace("action的偵聽器: " + event);
}
private function anotherHandler(event:Event):void {
trace("KingdaPlaySC的偵聽器: " + event);
}
}
}
import flash.events.EventDispatcher;
import flash.events.Event;
class KingdaSampleDispatcher extends EventDispatcher {
public static var ACTION:String = "action";
//如果你需要在自己類中某個方法中發送事件,那么示例如下
public function doSomething():void {
//你的代碼.....
//發送事件
dispatchEvent(new Event(KingdaSampleDispatcher.ACTION));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -