Actionscript 3 ActionScript 3按钮单击事件未触发

Actionscript 3 ActionScript 3按钮单击事件未触发,actionscript-3,flash,button,mouseevent,event-listener,Actionscript 3,Flash,Button,Mouseevent,Event Listener,所以现在,在我的flash游戏中,在不知疲倦地使用我的重启按钮之后,这个按钮仍然不会注册点击 以下是按钮的代码: 为什么我认为问题出在MouseEvent.CLICK上,因为跟踪标志没有显示 package { import flash.display.SimpleButton; import flash.events.MouseEvent; import flash.text.TextField; import flash.text.TextFormat;

所以现在,在我的flash游戏中,在不知疲倦地使用我的重启按钮之后,这个按钮仍然不会注册点击

以下是按钮的代码: 为什么我认为问题出在MouseEvent.CLICK上,因为跟踪标志没有显示

package 
{
    import flash.display.SimpleButton;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.ui.Mouse;
    /**
      * ...
      * @author Andrew Xia
      */
    public class RestartButton extends SimpleButton
    {
        public function RestartButton(setX:Number, setY:Number)
        {
            this.x = setX;
            this.y = setY;
            addEventListener(MouseEvent.CLICK, onClick);
        }

        public function onClick(event:MouseEvent):void
        {
                        trace("HELLO!");
            dispatchEvent( new NavigationEvent( NavigationEvent.RESTART ));
        }
    }
 }
下面是我添加按钮的屏幕代码:

  package 
  {
    import flash.display.MovieClip;
    import flash.display.SimpleButton;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.ui.Mouse;
    /**
     * ...
     * @author Andrew Xia
     */
    public class GameOverScreen extends MovieClip 
    {
        public var restartButton:RestartButton;
        public var scoreLabel:TextField;
        public var scoreBox:TextField;

        public function GameOverScreen()
        {
            Mouse.show();
            restartButton = new RestartButton(0, 108);
            addChild(restartButton);

            var textFormat = new TextFormat();
            textFormat.size = 54;

            scoreLabel = new TextField();
            scoreLabel.x = -185;
            scoreLabel.y = -36.75;
            scoreLabel.height = 73.5;
            scoreLabel.width = 185;
            scoreLabel.text = "SCORE: ";
            scoreLabel.textColor = 0xFFFFFF;
            scoreLabel.setTextFormat(textFormat);
            addChild(scoreLabel);

            scoreBox = new TextField();
            scoreBox.x = 0;
            scoreBox.y = -36.75;
            scoreBox.height = 73.5;
            scoreBox.width = 143;
            scoreBox.text = (String)(Main.playerScore);
            scoreBox.textColor = 0xFFFFFF;
            scoreBox.setTextFormat(textFormat);
            addChild(scoreBox);
        }
    }
}

请帮帮我,这个问题让我抓狂,我相信这可能是我犯的一个非常愚蠢的错误,但如果你们能帮我解决,我将不胜感激。

我看不到你们为任何按钮状态添加了任何DisplayObject。如果没有可点击的东西,点击永远不会发生

尝试将此作为RestartButton类:

package 
{
    import flash.display.SimpleButton;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.ui.Mouse;

    public class RestartButton extends SimpleButton
    {
        public function RestartButton(setX:Number, setY:Number)
        {
           super(GRAPHICS_FOR_UP, OVER, DOWN, HIT); // the object can repeat

           this.x = setX;
           this.y = setY;
           addEventListener(MouseEvent.CLICK, onClick);
        }

        public function onClick(event:MouseEvent):void
        {
                    trace("HELLO!");
            dispatchEvent( new NavigationEvent( NavigationEvent.RESTART ));
        }
    }
}
如果出于某种原因您不想添加图形,只需使用

super(null, null, null, HIT_GRAPHICS);

现在您可以单击按钮。

首先,其他跟踪是否有效?如果否,则您是在发布模式下编译,而跟踪只是不编译。第二,您可以将时髦的代码添加到侦听器中,然后测试这些代码是否有效。说parent.graphics.moveTo0,0;parent.graphics.lineto500500;因此,在精灵之上的游戏将得到一条线。如果它能工作,你必须将导航事件分配给其他类,而不是这个类。这个类很可能是GUI设计的,因此命中、向上、向上、向下的图形是预先放置的。但是是的,命中区域是需要注意的。我自己没有遇到这个问题,但是我认为如果他为这个对象生成了自定义类,并且super没有定义,那么编译时会生成一个空的super,并且对SimpleButton对象的实际引用是空的,但是对于DisplayObject它们是可以的。。。很难知道真正的问题,只是猜测:从技术上讲,这甚至不是一个编程问题,只是故障排除。谢谢你的回答。但是vesper是对的,我已经通过GUI设计了按钮,我不相信它是热门区域,因为按钮通过动画。创造性魔术谢谢你,我会看一看,是的,你是对的,这是更多的故障排除,但我真的一直在工作关于这一点,我只想结束这个bug:P无论如何,谢谢你们的帮助@AndrewX我试着粘贴你的代码,效果很好。我认为要么是上面的东西覆盖了你的按钮,要么是你处于发布模式,编译器在编译时会删除跟踪消息。