Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. package {
  2.  
  3. import flash.display.MovieClip;
  4. import flash.events.MouseEvent;
  5. public class DocumentClass extends MovieClip
  6. {
  7. public var playScreen:AvoiderGame;
  8. public var gameOverScreen:GameOverScreen;
  9. public var menuScreen:MenuScreen;
  10. public var creditScreen:CreditScreen;
  11.  
  12. public function DocumentClass()
  13. {
  14. menuScreen = new MenuScreen();
  15. menuScreen.addEventListener( NavigationEvent.START, onRequestStart );
  16. menuScreen.x = 0;
  17. menuScreen.y = 0;
  18. addChild( menuScreen );
  19. }
  20.  
  21. public function onAvatarDeath( avatarEvent:AvatarEvent ):void
  22. {
  23. var finalScore:Number = playScreen.getFinalScore();
  24. var finalClockTime:Number = playScreen.getFinalClockTime();
  25.  
  26. gameOverScreen = new GameOverScreen();
  27. gameOverScreen.addEventListener( NavigationEvent.RESTART, onRequestRestart );
  28. gameOverScreen.x = 0;
  29. gameOverScreen.y = 0;
  30. gameOverScreen.setFinalScore( finalScore );
  31. gameOverScreen.setFinalClockTime( finalClockTime );
  32. addChild( gameOverScreen );
  33.  
  34. playScreen = null;
  35. }
  36.  
  37. public function onRequestRestart( navigationEvent:NavigationEvent ):void
  38. {
  39. restartGame();
  40. }
  41.  
  42. public function onRequestStart( navigationEvent:NavigationEvent ):void
  43. {
  44. playScreen = new AvoiderGame();
  45. playScreen.addEventListener( AvatarEvent.DEAD, onAvatarDeath );
  46. playScreen.x = 0;
  47. playScreen.y = 0;
  48. addChild( playScreen );
  49.  
  50. menuScreen = null;
  51. }
  52.  
  53. public function restartGame():void
  54. {
  55. playScreen = new AvoiderGame();
  56. playScreen.addEventListener( AvatarEvent.DEAD, onAvatarDeath );
  57. playScreen.x = 0;
  58. playScreen.y = 0;
  59. addChild( playScreen );
  60.  
  61. gameOverScreen = null;
  62. }
  63.  
  64. public function showCredit():void
  65. {
  66. creditScreen = new CreditScreen;
  67. //add credit
  68. addChild(creditScreen);
  69. creditScreen.creditButton.addEventListener(MouseEvent.CLICK, clickCredit);
  70. creditScreen.x = 0;
  71. creditScreen.y = 0;
  72.  
  73. }
  74.  
  75. public function clickCredit(e:MouseEvent):void
  76. {
  77. menuScreen = null;
  78. creditScreen.creditButton.addEventListener(MouseEvent.CLICK, clickCredit);
  79. showCredit();
  80. }
  81.  
  82. }
  83.  
  84. package {
  85. import flash.events.*;
  86.  
  87. public class NavigationEvent extends Event
  88. {
  89. public static const RESTART:String = "restart";
  90. public static const START:String = "start";
  91. public static const CREDIT:String = "credit";
  92.  
  93. public function NavigationEvent( type:String, bubbles:Boolean = false, cancelable:Boolean = false )
  94. {
  95. super( type, bubbles, cancelable );
  96.  
  97. }
  98.  
  99. public override function clone():Event
  100. {
  101. return new NavigationEvent( type, bubbles, cancelable );
  102. }
  103.  
  104. public override function toString():String
  105. {
  106. return formatToString( "NavigationEvent", "type", "bubbles", "cancelable", "eventPhase" );
  107. }
  108.  
  109. }
  110.  
  111. package {
  112. import flash.display.MovieClip;
  113. import flash.display.SimpleButton;
  114. import flash.events.MouseEvent;
  115.  
  116. public class MenuScreen extends MovieClip
  117. {
  118. public function MenuScreen()
  119. {
  120. startButton.addEventListener( MouseEvent.CLICK, onClickStart );
  121. }
  122.  
  123. public function onClickStart( mouseEvent:MouseEvent ):void
  124. {
  125. dispatchEvent( new NavigationEvent( NavigationEvent.START ) );
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement