PageRenderTime 84ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/states/StatesMaster.as

https://gitlab.com/gideonmarked/CokeInstagram
ActionScript | 123 lines | 102 code | 15 blank | 6 comment | 3 complexity | 55ac13241205ab9ff4e044b0afaf4a92 MD5 | raw file
  1. package states
  2. {
  3. import flash.display.Sprite;
  4. import flash.events.MouseEvent;
  5. import flash.media.SoundChannel;
  6. import starling.core.Starling;
  7. import starling.display.Button;
  8. import starling.display.Quad;
  9. import starling.display.Sprite;
  10. import starling.events.Event;
  11. public class StatesMaster extends Sprite
  12. {
  13. private var currentState:Sprite;
  14. public var selectedItem:String;
  15. public var commentContent:String;
  16. public var satisfactionLevel:int;
  17. public var totalArray:Array;
  18. public var NEXT_STATE:String = "start";
  19. public static const SWITCH:String = "switch";
  20. private var soundChannel:SoundChannel;
  21. private var q:Quad;
  22. private var b:Button;
  23. private var s:flash.display.Sprite;
  24. public function StatesMaster()
  25. {
  26. selectedItem = "";
  27. satisfactionLevel = 0;
  28. totalArray = new Array();
  29. this.addEventListener( Event.ADDED_TO_STAGE, initialize );
  30. }
  31. private function initialize():void
  32. {
  33. this.removeEventListener( Event.ADDED_TO_STAGE, initialize );
  34. this.addEventListener( Event.REMOVED_FROM_STAGE, destroy );
  35. Assets.loadAssets();
  36. Assets.assetsManager.loadQueue(function(ratio:Number):void
  37. {
  38. trace("Loading assets, progress:", ratio);
  39. // -> When the ratio equals '1', we are finished.
  40. if (ratio == 1.0)
  41. {
  42. // soundChannel = Assets.assetsManager.getSound("background").play(0,99);
  43. Assets.aspect = stage.stageHeight / 1920;
  44. switchState( new StartState() );
  45. createHomeButton();
  46. }
  47. });
  48. }
  49. private function createHomeButton():void
  50. {
  51. s = new flash.display.Sprite();
  52. s.graphics.beginFill(0x000000, 0);
  53. s.graphics.drawRect( 0, 0, 100 * Assets.aspect, 100 * Assets.aspect );
  54. s.graphics.endFill();
  55. s.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
  56. Starling.current.nativeStage.addChild(s);
  57. }
  58. protected function onMouseDown(event:MouseEvent):void
  59. {
  60. switchState( new StartState() );
  61. }
  62. private function destroy():void
  63. {
  64. this.removeEventListener( Event.REMOVED_FROM_STAGE, destroy );
  65. }
  66. public function switchState(state:Sprite):void
  67. {
  68. if(contains(currentState))
  69. {
  70. removeChild(currentState);
  71. currentState = null;
  72. }
  73. currentState = state;
  74. addChild(currentState);
  75. currentState.addEventListener( StatesMaster.SWITCH, onSwitchState );
  76. }
  77. private function onSwitchState(event:Event):void
  78. {
  79. switch(NEXT_STATE)
  80. {
  81. case "start":
  82. {
  83. // soundChannel.soundTransform.volume = 0;
  84. switchState( new StartState() );
  85. break;
  86. }
  87. case "camera":
  88. {
  89. // soundChannel.soundTransform.volume = 0;
  90. switchState( new CameraState() );
  91. break;
  92. }
  93. case "selection":
  94. {
  95. // soundChannel.soundTransform.volume = 0;
  96. switchState( new SelectionState() );
  97. break;
  98. }
  99. case "result":
  100. {
  101. // soundChannel.soundTransform.volume = 0;
  102. switchState( new ResultState() );
  103. break;
  104. }
  105. }
  106. }
  107. }
  108. }