因此,我不得不重写一个我正在进行的项目,以避免使用Starling框架和扩展羽毛,现在我正在尝试使按钮工作。我目前的代码是
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都是我的项目中的类。
发布于 2014-02-17 05:51:35
您没有提供hitTestState按钮-它是不活动的。你只放弃了他和悬停状态。
startGameButton = new SimpleButton(new playButtonUp(), new playButtonDown(), new playButtonDown(), new playButtonDown());
https://stackoverflow.com/questions/21821212
复制相似问题