Actionscript 3 MouseeEvent侦听器不使用SimpleButton AS3
因此,我不得不重写一个我正在进行的项目,以避免使用Starling框架和扩展Feathers,现在我正试图让按钮正常工作。我的代码目前是Actionscript 3 MouseeEvent侦听器不使用SimpleButton AS3,actionscript-3,flash,Actionscript 3,Flash,因此,我不得不重写一个我正在进行的项目,以避免使用Starling框架和扩展Feathers,现在我正试图让按钮正常工作。我的代码目前是 package { import flash.display.Bitmap; import flash.display.SimpleButton; import flash.events.MouseEvent; /** * ... * @author Fluzzarn */ public class StartScreen extends S
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对象都有MouseeEvent侦听器,那么代码就可以正常工作,但是当我将侦听器添加到按钮本身时,它永远不会触发。这可能是愚蠢的事情,但我的谷歌fu现在不适合我
编辑:Screen只是一个基类,我让游戏中的每个屏幕都从中扩展,例如GameScreen、StartScreen、OptionScreen都是我项目中的类您没有提供hitTestState按钮-它处于非活动状态。你只给了他一个悬停状态
startGameButton=newsimplebutton(new playButtonUp(),new playButtonDown(),new playButtonDown(),new playButtonDown())
为什么要扩展Screen
?Screen只是一个基类,其他类为了在Main中切换而扩展到它