2010-10-17 237 views
2

我有帶有mouse_over,mouse_out和CLICK事件的按鈕。但是當我點擊按鈕時,它將我帶到另一個框架,並嘗試觸發mouse_out事件。我如何阻止這種情況發生?當鼠標點擊觸發時,如何停止mouse_out觸發

act1_btn.addEventListener(MouseEvent.CLICK,act1Pressed);
act1_btn.addEventListener(MouseEvent.MOUSE_OVER,act1Over); act1_btn.addEventListener(MouseEvent.MOUSE_OUT,act1Out); act1_btn.addEventListener(Event.ENTER_FRAME,act1EnterFrame);

function act1Over(e:MouseEvent):void { trace(「over」); act1Animating = true; logo_1.visible = true; bubble.visible = true; txt1.visible = true; }

function act1Out(e:MouseEvent):void { act1Animating = false; logo_1.visible = false; bubble.visible = false; txt1.visible = false; }

功能act1EnterFrame(E:事件):無效 { 如果(act1Animating & & e.target.scaleY < 1.1) { e.target.scaleY + = 0.02; e.target.scaleX + = 0.02;

}

如果(act1Animating & & e.target.scaleY> 1!) { e.target.scaleY - = 0.02; e.target.scaleX - = 0.02; } }

功能act1Pressed(E:MouseEvent)方法:無效 { 跡( 「點擊」); act1Animating = false; logo_1.visible = false; bubble.visible = false; txt1.visible = false; gotoAndStop(2); }

回答

2

這裏有兩種方法來處理這個問題:

1)只有在指定的MOUSE_OVER處理程序MOUSE_OUT監聽器,然後將其刪除的MOUSE_OUT處理程序完成後。即,

function act1Over(e:MouseEvent):void { 
    /* your code */ 
    act1_btn.addEventListener(MouseEvent.MOUSE_OUT, act1Out); 
} 

function act1Out(e:MouseEvent):void { 
    /* your code */ 
    act1_btn.removeEventListener(MouseEvent.MOUSE_OUT, act1Out); 
} 

2)使用stopPropagation()在點擊處理程序:

function act1Pressed(e:MouseEvent):void { 
    /* your code */ 
    e.stopPropagation(); 
} 

此外,在未來,請使用代碼標籤來標記你的代碼!

+0

非常感謝你 – 2010-10-18 08:19:30

0

當你點擊一個按鈕,你將會觸發鼠標懸停& mouseOut事件,如果你不想Click事件後觸發mouseout事件,那麼你就應該刪除mouseout事件偵聽器的Click事件偵聽器。

這意味着爲了確保在MouseOver時有一個MouseOut偵聽器,您應該在MouseOver偵聽器中添加您的MouseOut偵聽器。

最後,您應該刪除MouseOut偵聽器中的MouseOut事件偵聽器。

+0

不客氣;) – PatrickS 2010-10-18 10:00:03

2

改爲給ROLL_OVER和ROLL_OUT MouseEvent一個鏡頭可能不是一個壞主意。當有人翻轉物體時,這些只會發射一次,或者是推出,而不是連續發射。

+0

ROLL_OVER和ROLL_OUT是爲我修復它。謝謝。 – 2010-11-04 23:48:24