ActionScript 3 Button CLICK event not firing
So right now after tirelessly working with my restart button in my flash
game the button still will not register the click.
Here is the code for the button: Why I think the problem is with the
MouseEvent.CLICK because the trace() flag doesn't show up.
package
{
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.ui.Mouse;
/**
* ...
* @author Andrew Xia
*/
public class RestartButton extends SimpleButton
{
public function RestartButton(setX:Number, setY:Number)
{
this.x = setX;
this.y = setY;
addEventListener(MouseEvent.CLICK, onClick);
}
public function onClick(event:MouseEvent):void
{
trace("HELLO!");
dispatchEvent( new NavigationEvent( NavigationEvent.RESTART ));
}
}
}
And here is the code for the screen that I added the button to:
package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.ui.Mouse;
/**
* ...
* @author Andrew Xia
*/
public class GameOverScreen extends MovieClip
{
public var restartButton:RestartButton;
public var scoreLabel:TextField;
public var scoreBox:TextField;
public function GameOverScreen()
{
Mouse.show();
restartButton = new RestartButton(0, 108);
addChild(restartButton);
var textFormat = new TextFormat();
textFormat.size = 54;
scoreLabel = new TextField();
scoreLabel.x = -185;
scoreLabel.y = -36.75;
scoreLabel.height = 73.5;
scoreLabel.width = 185;
scoreLabel.text = "SCORE: ";
scoreLabel.textColor = 0xFFFFFF;
scoreLabel.setTextFormat(textFormat);
addChild(scoreLabel);
scoreBox = new TextField();
scoreBox.x = 0;
scoreBox.y = -36.75;
scoreBox.height = 73.5;
scoreBox.width = 143;
scoreBox.text = (String)(Main.playerScore);
scoreBox.textColor = 0xFFFFFF;
scoreBox.setTextFormat(textFormat);
addChild(scoreBox);
}
}
}
Please help, this problem has been driving me crazy and I'm sure its
probably just a really stupid error on my part but I would appreciate it
immensely if you guys can help me out.
No comments:
Post a Comment