Saturday, September 1, 2007

Reproduction Robe Titanic Kate Winslet



Preloader in AS3


in pure AS3 Since everything is placed in the first frame, You can not create prelodera because it will start only after everything is loaded in the first frame. What to do? There is a frame called metadata, which makes the class passed as a parameter is run in the first frame, and the whole is transferred to another cage. Unfortunately, there are drawbacks to light. Our preloader becomes the root. What does this mean? In our main class can not be appealed to the stage because they will get an error about not referring to an existing item (can get around this, but more on that later). Furthermore, everything that relates to stage such StageScaleMode must be preloaderze, probably SWF metadata is also (have not checked this). If you are using things like Google is Tweener.init Tweener () will also be placed in the preloader class.

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