Guest User

Untitled

a guest
Sep 24th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.DisplayObject;
  4.     import flash.display.MovieClip;
  5.     import flash.display.StageAlign;
  6.     import flash.display.StageScaleMode;
  7.     import flash.events.Event;
  8.     import flash.events.IOErrorEvent;
  9.     import flash.events.ProgressEvent;
  10.     import flash.utils.getDefinitionByName;
  11.    
  12.     /**
  13.      * ...
  14.      * @author Justin Wolf
  15.      */
  16.     public class Preloader extends MovieClip
  17.     {
  18.        
  19.         public function Preloader()
  20.         {
  21.             if (stage) {
  22.                 stage.scaleMode = StageScaleMode.NO_SCALE;
  23.                 stage.align = StageAlign.TOP_LEFT;
  24.             }
  25.             addEventListener(Event.ENTER_FRAME, checkFrame);
  26.             loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress);
  27.             loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);
  28.            
  29.             // TODO show loader
  30.         }
  31.        
  32.         private function ioError(e:IOErrorEvent):void
  33.         {
  34.             trace(e.text);
  35.         }
  36.        
  37.         private function progress(e:ProgressEvent):void
  38.         {
  39.             // TODO update loader
  40.         }
  41.        
  42.         private function checkFrame(e:Event):void
  43.         {
  44.             if (currentFrame == totalFrames)
  45.             {
  46.                 stop();
  47.                 loadingFinished();
  48.             }
  49.         }
  50.        
  51.         private function loadingFinished():void
  52.         {
  53.             removeEventListener(Event.ENTER_FRAME, checkFrame);
  54.             loaderInfo.removeEventListener(ProgressEvent.PROGRESS, progress);
  55.             loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, ioError);
  56.            
  57.             // TODO hide loader
  58.            
  59.             startup();
  60.         }
  61.        
  62.         private function startup():void
  63.         {
  64.             var mainClass:Class = getDefinitionByName("Main") as Class;
  65.             addChild(new mainClass() as DisplayObject);
  66.         }
  67.        
  68.     }
  69.    
  70. }
Add Comment
Please, Sign In to add comment