1
我想刪除按鈕上的事件按鈕,所以當按下按鈕時,動畫完成,然後再次按下按鈕。但基於我的代碼下面你可以多次按下按鈕,只要你喜歡:刪除eventListener不在按鈕上工作AS3 - 閃光燈
var LeftButt:MovieClip = new left_button();
var RightButt:MovieClip = new right_button();
var topClip:Sprite = new Sprite();
addChild(topClip);
LeftButt.addEventListener(MouseEvent.MOUSE_UP, function(e){moveItems(e, "left");});
RightButt.addEventListener(MouseEvent.MOUSE_UP, function(e){moveItems(e, "right");});
function clothingApp(event:MouseEvent):void{
topClip.addChild(RightButt);
topClip.addChild(LeftButt);
}
function moveItems(event:MouseEvent, SlideDirection:String):void{
LeftButt.removeEventListener(MouseEvent.MOUSE_UP, function(e){moveItems(e, "left");});
RightButt.removeEventListener(MouseEvent.MOUSE_UP, function(e){moveItems(e, "right");});
trace(SlideDirection);
}
因此從技術上講,因爲我從來沒有成立了事件監聽再此代碼應只運行一次。但是,您可以多次按下按鈕,只要你喜歡。
所以我把我的addeventlistener移到了我的函數外面,remove仍然在裏面。我仍然可以按我想要的次數按下它。 – Denoteone 2012-02-28 17:11:21
@Denoteone,你不應該將addEventLIstener移出函數,你需要將函數移出addEventListener。 – 2012-02-28 17:26:21
AH-HA(燈泡)我明白你現在在說什麼。將測試並確認它的工作原理。謝謝+1 – Denoteone 2012-02-28 17:39:27