Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.MovieClip;
- import flash.events.MouseEvent;
- public class DocumentClass extends MovieClip
- {
- public var playScreen:AvoiderGame;
- public var gameOverScreen:GameOverScreen;
- public var menuScreen:MenuScreen;
- public var creditScreen:CreditScreen;
- public function DocumentClass()
- {
- menuScreen = new MenuScreen();
- menuScreen.addEventListener( NavigationEvent.START, onRequestStart );
- menuScreen.x = 0;
- menuScreen.y = 0;
- addChild( menuScreen );
- }
- public function onAvatarDeath( avatarEvent:AvatarEvent ):void
- {
- var finalScore:Number = playScreen.getFinalScore();
- var finalClockTime:Number = playScreen.getFinalClockTime();
- gameOverScreen = new GameOverScreen();
- gameOverScreen.addEventListener( NavigationEvent.RESTART, onRequestRestart );
- gameOverScreen.x = 0;
- gameOverScreen.y = 0;
- gameOverScreen.setFinalScore( finalScore );
- gameOverScreen.setFinalClockTime( finalClockTime );
- addChild( gameOverScreen );
- playScreen = null;
- }
- public function onRequestRestart( navigationEvent:NavigationEvent ):void
- {
- restartGame();
- }
- public function onRequestStart( navigationEvent:NavigationEvent ):void
- {
- playScreen = new AvoiderGame();
- playScreen.addEventListener( AvatarEvent.DEAD, onAvatarDeath );
- playScreen.x = 0;
- playScreen.y = 0;
- addChild( playScreen );
- menuScreen = null;
- }
- public function restartGame():void
- {
- playScreen = new AvoiderGame();
- playScreen.addEventListener( AvatarEvent.DEAD, onAvatarDeath );
- playScreen.x = 0;
- playScreen.y = 0;
- addChild( playScreen );
- gameOverScreen = null;
- }
- public function showCredit():void
- {
- creditScreen = new CreditScreen;
- //add credit
- addChild(creditScreen);
- creditScreen.creditButton.addEventListener(MouseEvent.CLICK, clickCredit);
- creditScreen.x = 0;
- creditScreen.y = 0;
- }
- public function clickCredit(e:MouseEvent):void
- {
- menuScreen = null;
- creditScreen.creditButton.addEventListener(MouseEvent.CLICK, clickCredit);
- showCredit();
- }
- }
- package {
- import flash.events.*;
- public class NavigationEvent extends Event
- {
- public static const RESTART:String = "restart";
- public static const START:String = "start";
- public static const CREDIT:String = "credit";
- public function NavigationEvent( type:String, bubbles:Boolean = false, cancelable:Boolean = false )
- {
- super( type, bubbles, cancelable );
- }
- public override function clone():Event
- {
- return new NavigationEvent( type, bubbles, cancelable );
- }
- public override function toString():String
- {
- return formatToString( "NavigationEvent", "type", "bubbles", "cancelable", "eventPhase" );
- }
- }
- package {
- import flash.display.MovieClip;
- import flash.display.SimpleButton;
- import flash.events.MouseEvent;
- public class MenuScreen extends MovieClip
- {
- public function MenuScreen()
- {
- startButton.addEventListener( MouseEvent.CLICK, onClickStart );
- }
- public function onClickStart( mouseEvent:MouseEvent ):void
- {
- dispatchEvent( new NavigationEvent( NavigationEvent.START ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement