除非對象是在顯示階段,stage
對象將是未定義的(或空)。你必須addChild
對象爲stage
對象有一個值。
編輯:也許你可以在事件處理程序中處理這個?
protected function clickHandler(e :Event) :void {
if (e.target.stage) {
e.target.stage.removeEventListener(...);
}
}
EDIT2:靜態方法沒有一個階段,所以解決你的問題,你可以讓你的主類單身,像這樣的工作:
public class Main {
static private var instance :Main;
static public function getInstance() :Main {
if (Main.instance == undefined) {
Main.instance = new Main();
}
return Main.instance;
}
// The rest of the class goes here
}
// snip
import Main;
public static function disableVcam():void {
trace("disable");
Main.getInstance().stage.removeEventListener(MouseEvent.MOUSE_MOVE, movevC);
}
如果你的主級是項目的主要類,您需要在構造函數中分配變量的靜態值instance
。
我有使用Event.ADDED_TO_STAGE添加到階段的類,但只有當從另一個動態類的按鈕被推入時纔會調用該類,並且該類只有其他類的幾層。我只能得到trace語句,但不能得到mouseevent的工作 – Hwang 2010-04-13 09:52:18
也許你可以嘗試在事件處理程序中使用'event.target.stage'。 – 2010-04-13 09:58:47
nope。似乎沒有工作。 – Hwang 2010-04-13 11:35:58