2

我正在尝试取消此 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
    }
}

如何取消事件悬停按钮?在此示例中,按钮会在您悬停时做出响应。

4

1 回答 1

0

您的悬停事件似乎被添加到 Main Not the Button 上。尝试将事件侦听器放在您声明的 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);
}
于 2016-10-14T04:21:00.193 回答