所以我想要一種設置事件的方式,以便我可以傳遞數據而不會產生閉包\內存泄漏。這是據我已經得到:如何修改現有的AS3事件以便我可以傳遞數據?
package com.events {
import flash.events.Event;
public class CustomEvent extends Event {
public static const REMOVED_FROM_STAGE:String = "removedFromStage";
public var data:*;
public function CustomEvent(type:String, customData:*=null, bubbles:Boolean=false, cancelable:Boolean=false) {
super(type, bubbles, cancelable);
this.data = customData;
}
public override function clone():Event {
return new CustomEvent(type, data, bubbles, cancelable);
}
public override function toString():String {
return formatToString("CustomEvent", "type", "data", "bubbles", "cancelable", "eventPhase");
}
}
}
這讓我以下行爲:
function testme(e:Event) {
trace(e);
}
test_mc.addEventListener(CustomEvent.REMOVED_FROM_STAGE, testme);
test_mc.dispatchEvent(new CustomEvent(CustomEvent.REMOVED_FROM_STAGE, 42));
//Traces [CustomEvent type="removedFromStage" data=42 bubbles=false cancelable=false eventPhase=2]
removeChild(test_mc);
//Traces [Event type="removedFromStage" bubbles=false cancelable=false eventPhase=2]
我的目標是讓我想通過獲得從事件閃光燈通過自定義數據,而不僅僅是我開火的那個。例如,如果我想將一個movieclip和一個loader.COMPLETE事件一起傳遞給所產生的位圖,該怎麼辦?
可否請您舉一個例子你的CustomEvent類 – 2010-02-04 20:34:00
沒關係。 :) http://www.charglerode.com/blog/?p=51 – 2010-02-04 20:57:47