好,改變isStartDrawMarker的價值不會叫startDrawMarker方法,這就是爲什麼^^
使用AS3,您可以在想要在變量更改上添加行爲時創建get/set。 爲此重新命名類變量
public var isStartDrawMarker
在
private var _isStartDrawMarker
而且使用的get/set像下面
/**
* get the current value
*/
public function get isStartDrawMarker():Boolean
{
return _isStartDrawMarker;
}
/**
* change the current value AND automatically add/remove a mousedown listener on the stage
*/
public function set isStartDrawMarker(value:Boolean):void
{
_isStartDrawMarker = value;
if (_isStartDrawMarker == true) {
stage.addEventListener(MouseEvent.MOUSE_DOWN, onDownMarker);
} else {
stage.removeEventListener(MouseEvent.MOUSE_DOWN, onDownMarker);
}
}
這裏是如何在你的代碼中使用它(請注意,你總是使用isStartDrawMarker而不是_isStartDrawMarker巫婆是私人的)
this.isStartDrawMarker = true; // will set to true AND add the listener
this.isStartDrawMarker = false; // will set to false AND remove the listener
或
myClass.isStartDrawMarker = true; // will set to true AND add the listener
myClass.isStartDrawMarker = false; // will set to false AND remove the listener
我猜測我們將需要更多的信息來幫助你找出問題所在。 – Bob
這個實現,你必須: - isStartDrawMarker 的變化值 - 調用startDrawMarker方法來刪除/如果你想做我在一個單一的舉動我已經加入下面 長的答案另一個解決方法是刪除添加監聽 onDownMarker MouseEvent.MOUSE_UP事件的監聽器^^ – YopSolo