MouseEvent侦听器不使用SimpleButton AS3

时间:2014-02-17 05:08:54

标签: actionscript-3 flash

所以我不得不重写一个我正在努力的项目,不使用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都是我项目中的所有类

1 个答案:

答案 0 :(得分:0)

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

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