actionscript 3 - Correct method of incorporating Starling with Preloader -


hi know best method of adding preloader. when content loaded create instance of starling framework. here have:

import flash.display.loader; import flash.display.sprite; import flash.events.event; import loaders.preloader; import starling.core.starling;      //main class container  public class game extends sprite  {     //preloader class     private var _loader:preloader;      //starling instance     private var _starling:starling;      //constructor initialise game     public function game():void      {         this.addeventlistener(event.added_to_stage, onaddedtostage)     }      private function onaddedtostage(e:event):void      {         this.removeeventlistener(event.added_to_stage, onaddedtostage);          _loader = new preloader();         addchild(_loader);          _loader.addeventlistener("loaded_game", ongameloaded);     }      private function ongameloaded(e:event):void      {         trace("game loaded");         _starling = new starling(game,stage,null,null,"auto","baseline");         _starling.start();     }  } 

this preloader class:

package loaders { import flash.events.event; import flash.display.sprite; import flash.text.textfield; import flash.text.textfieldautosize;  public class preloader extends sprite {     private var textloaded:textfield;      public function preloader()     {         this.addeventlistener(event.added_to_stage, onaddedtostage);     }      private function onaddedtostage(event:event):void     {         // remove added stage listener         this.removeeventlistener(event.added_to_stage, onaddedtostage);          textloaded = new textfield();         textloaded.x = 300;         textloaded.y = 300;         textloaded.border = true;         textloaded.autosize = "center";         addchild(textloaded);          //loop current load state         this.addeventlistener(event.enter_frame, loadgame);         this.addeventlistener(event.removed_from_stage, onremovedfromstage);     }      private function onremovedfromstage(event:event):void {         this.removeeventlistener(event.enter_frame, loadgame);         this.removeeventlistener(event.removed_from_stage, onremovedfromstage);     }      private function loadgame(e:event):void     {         //vars         var total:number = parent.stage.loaderinfo.bytestotal;         var loaded:number = parent.stage.loaderinfo.bytesloaded;          textloaded.text = math.floor((loaded/total)* 100) + "%";          if (total == loaded)         {             this.removeeventlistener(event.enter_frame, loadgame);             dispatchevent(new event("loaded_game", true));         }     }  }//end of class 

}

is best way of doing or there more efficient, practical option? can see making use of flash classes before instantiate starling? preloader textfield listing loaded, should allow application load faster.

don't think make more sense create external swf preloads game? better solution incorporating preloader main game file.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -