Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // a navigation event
- package
- {
- import flash.events.Event;
- public class NavigationEvent extends Event
- {
- public static const RESTART:String = "restart"; // defining a constant for RESTART
- public static const START:String = "start"; // constant for START
- public static const MENUSCREEN:String = "menu"; // constant for MENU
- public function NavigationEvent(type:String)
- {
- super(type);
- }
- }
- }
- // below is the code for the Game Over screen, the restart button works and calls the navigation event, but the onClickMenu function gives a compiler error "TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@271aa089 to NavigationEvent."
- // Game Over screen class
- package
- {
- import flash.display.MovieClip;
- import flash.display.SimpleButton;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import flash.ui.Mouse;
- public class GameOverScreen extends MovieClip
- {
- public function GameOverScreen()
- {
- Mouse.show(); // show mouse cursor
- restartButton.addEventListener( MouseEvent.CLICK, onClickRestart ); // add click listener to button
- menuButton.addEventListener( MouseEvent.CLICK, onClickMenu); // add menu button listener
- }
- public function onClickRestart(mouseEvent:MouseEvent):void // restarts the game when the restart button is clicked!
- {
- dispatchEvent(new NavigationEvent(NavigationEvent.RESTART));
- }
- public function setFinalScore(scoreValue:Number):void // sets the final score display
- {
- finalScore.text = scoreValue.toString();
- }
- public function onClickMenu(navigationEvent:NavigationEvent):void // brings you back to the menu!
- {
- dispatchEvent(new NavigationEvent(NavigationEvent.MENUSCREEN));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment