![](/img/trans.png)
[英]Flash Actionscript 3 SimpleButton doesn't have focusEnabled property?
[英]stopImmediatePropagation doesn't work for SimpleButton
我正在嘗試取消此actionscript3代碼中的事件:
public class Main extends Sprite
{
public function Main()
{
this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
protected function onAddedToStage(event:Event):void
{
this.addEventListener(MouseEvent.MOUSE_OVER, onOver, true, int.MAX_VALUE);
var btn:SimpleButton = new SimpleButton(
createBtnState(0x0000FF),
createBtnState(0x00FFFF),
createBtnState(0x00FF00),
createBtnState(0x0000FF));
btn.x = stage.stageWidth - btn.width >> 1;
btn.y = stage.stageHeight - btn.height >> 1;
addChild(btn);
}
private function createBtnState(color:uint):Sprite
{
var s:Sprite = new Sprite();
s.graphics.beginFill(color, 1);
s.graphics.drawRect(0,0,100,20);
s.graphics.endFill();
return s;
}
protected function onOver(event:MouseEvent):void
{
event.stopImmediatePropagation(); //Don't work
}
}
如何取消懸停按鈕的事件? 在此示例中,當您將鼠標懸停時,按鈕會做出響應。
您的懸停事件似乎已添加到“主要”而不是“按鈕”上。 嘗試將事件偵聽器放在您聲明的btn上。
protected function onAddedToStage(event:Event):void
{
//this.addEventListener(MouseEvent.MOUSE_OVER, onOver, true, int.MAX_VALUE);
var btn:SimpleButton = new SimpleButton(
createBtnState(0x0000FF),
createBtnState(0x00FFFF),
createBtnState(0x00FF00),
createBtnState(0x0000FF));
btn.x = stage.stageWidth - btn.width >> 1;
btn.y = stage.stageHeight - btn.height >> 1;
addChild(btn);
btn.addEventListener(MouseEvent.MOUSE_OVER, onOver, true, int.MAX_VALUE);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.