【问题标题】:MouseEvent Listener not working with SimpleButton AS3MouseEvent 侦听器不适用于 SimpleButton AS3
【发布时间】:2014-03-16 06:49:49
【问题描述】:

所以我不得不重写我正在处理的一个项目,以不使用 Starling 框架和扩展 Feathers,现在我正试图让按钮工作。我的代码目前是

    package  
{
import flash.display.Bitmap;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
/**
 * ...
 * @author Fluzzarn
 */
public class StartScreen extends Screen 
{

    public var startGameButton:SimpleButton;
    public var optionsButton:SimpleButton;

    [Embed (source = "assets\\playGameButtonUp.png")]
    private var playButtonUp:Class
    [Embed (source = "assets\\playGameButtonDown.png")]
    private var playButtonDown:Class

    [Embed (source = "assets\\titleScreen.png")]
    private var backGround:Class;

    public function StartScreen() 
    {
        mouseChildren = true;
        super();
        startGameButton = new SimpleButton(new playButtonUp(), new playButtonDown());

        addChild(new backGround());
        addChild(startGameButton);
        startGameButton.addEventListener(MouseEvent.CLICK, goToGame);
        trace(startGameButton.getBounds(stage));
    }

    private function goToGame(e:MouseEvent):void 
    {
        trace("Mouse Clicked");
        Main(parent).goToGame();
    }


}

}

如果我只是让整个 StartScreen 对象具有 MouseEvent 侦听器,则代码将按预期工作,但是当我将侦听器添加到按钮本身时,它永远不会触发。这可能是一些愚蠢的事情,但我的 google-fu 现在不适合我。

编辑:屏幕只是一个基类,我的游戏中的每个屏幕都从它扩展而来,例如GameScreen、StartScreen、OptionScreen 都是我项目中的类

【问题讨论】:

  • 为什么要扩展Screen
  • Screen 只是其他类扩展的基类,以便在 Main 之间切换

标签: actionscript-3 flash


【解决方案1】:

您没有为按钮提供 hitTestState - 它处于非活动状态。你只给了他 up 和 hover 状态。

startGameButton = new SimpleButton(new playButtonUp(), new playButtonDown(), new playButtonDown(), new playButtonDown());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 2016-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多