actionscript 3 - as3 self preloaded (internal) in Document Class -
i've googled lot , couldn't find except timeline based pre loaders or external pre loaders (loading external swfs).
i'm looking document class preloaded has library symbols exported first frame.
please advise.
i have private variables inside document class referring exported clips.
public var menu:menu; public var brand:movieclip; public var container:movieclip; public var background:background; public var intro:intro; public var language:language;
plus lots of clips exported flash on frame 1, instance combobox, (screenshot below)
you need use root.loaderinfo
's bytestotal
, bytesloaded
properties.
when equal eachother, you've loaded 100% of swf , can manage should happen next accordingly.
sample:
package { import flash.display.sprite; import flash.events.event; /** * document class. */ public class document extends sprite { // constructor. public function document() { addeventlistener(event.enter_frame, _loadstatus); } // manage current status of preloader. private function _loadstatus(e:event):void { if(loadpercent >= 1) { removeeventlistener(event.enter_frame, _loadstatus); beginapplication(); } } // load complete, being application here. protected function beginapplication():void { trace("loaded."); } // returns number representing current application load percentage. protected function loadpercent():number { return root.loaderinfo.bytesloaded / root.loaderinfo.bytestotal; } } }
i must note exporting library symbols on first frame bad idea - need make sure aren't exported on first frame.
bonus: having above class base class of actual document class makes tidy application entry point (where begin coding application):
public class mydocument extends document { override protected function beginapplication():void { // application has loaded. // initialize code here. // // } }
Comments
Post a Comment