Preloader in AS3
First we create our preloader:
com.kuzimski
package {import
flash.display.DisplayObject;
import flash.display . MovieClip;
flash.display.StageAlign import, import
flash.display.StageScaleMode;
import flash.display.StageQuality;
import flash.events.Event;
import flash. utils.getDefinitionByName;
import caurina.transitions.Tweener;
public class Preloader extends MovieClip {
public function Preloader () {
Tweener. init (stage); / / these things that need to be root in this class we
stop (); / / we need to stay in the first frame
stage. scaleMode = StageScaleMode.NO_SCALE;
stage. align = StageAlign.TOP_LEFT;
Stage.showDefaultContextMenu = false ;
stage.quality = StageQuality.BEST;
addEventListener(Event.ENTER_FRAME, onEnterFrame );
}
private function onEnterFrame (event:Event):void
{
if (framesLoaded == totalFrames)
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame );
nextFrame ();
init ();
}
else
{
trace (root.loaderInfo.BytesLoaded+" / "+root.loaderInfo.BytesTotal);
}}
private function init (): void {
var mainClass: Class = Class getDefinitionByName ( SampleClass ")); / / create a class to instantiate our shit, we use getInstanceByName, so you do not have to add it in the first frame
if (mainClass) {
var app: Object = new mainClass (stage); / / here solved the problem of recourse to the stage, enough to pass the stage as a parameter to the main class, and there we can do with what we
addChild (app as DisplayObject); / / no, and finally add our main class of the scene. Here you should zwrocc note that in this way our class is not on top of the list wyswietalnych objects (for luck is a preloader)
}}}
now our principal class
package {
import flash.display . MovieClip;
[Frame (factoryClass = " com.kuzimski.Preloader ")] / / here we put our preloader to the first frame
public class SampleClass extends MovieClip {
private var myStage: Object ;
public function SampleClass (_stage: Object) {
myStage = _stage;
trace (MyStage.stageWidth);
}}}
do not know why I can not take advantage of events like the preloaderze
Progress and Complete (just do not odpalaja, fires only in August init) ... I would prefer it to be
on events because such a solution with totalFrames
not like me.
Based http://www.bit-101.com/blog/?p=946.
}
0 comments:
Post a Comment