首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MouseEvent侦听器不使用SimpleButton AS3

MouseEvent侦听器不使用SimpleButton AS3
EN

Stack Overflow用户
提问于 2014-02-17 05:08:54
回答 1查看 329关注 0票数 0

因此,我不得不重写一个我正在进行的项目,以避免使用Starling框架和扩展羽毛,现在我正在尝试使按钮工作。我目前的代码是

代码语言:javascript
复制
    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都是我的项目中的类。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-17 05:51:35

您没有提供hitTestState按钮-它是不活动的。你只放弃了他和悬停状态。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21821212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档