Skip to main content
BladePoint
Inspiring
February 6, 2013
Question

Pure AS3 self-preloader

  • February 6, 2013
  • 1 reply
  • 1710 views

My project originally had everything on the timeline, but I have since moved all the code to the document class, but some of my assets are still in the library and some of them are embedded. I'm trying to make a self-preloader that doesn't use any external files, but I can't seem to find a good tutorial that doesn't involve using the timeline. Can anyone point me to a pure AS3 self-preloader tutorial or tell me where I'm supposed to put everything?

This topic has been closed for replies.

1 reply

Inspiring
February 6, 2013

If you mean by "self-preloader" a pure Standalone as3 preloader:

var l:Loader = new Loader();

l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);

l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);

//this line has to be adapted to the name of your document class

l.load(new URLRequest("main.swf"));

function loop(e:ProgressEvent):void

{

    var kBytesLoaded:int = Math.round(e.bytesLoaded/1024);

    var kBytesTotal:int = Math.round(e.bytesTotal/1024);

    var perc:Number = kBytesLoaded / kBytesTotal;

    trace("PERCENT:"+perc);

}

function done(e:Event):void

{

    //this line for the stuff you might need to visually communicate the loading process and want to remove when loading is done

    removeChildAt(0);

    addChild(l);

}

BladePoint
Inspiring
February 6, 2013

By self-preloader, I mean 1 file. What you posted requires 2, right? The loader SWF and then the actual SWF.

Inspiring
February 6, 2013

Here is a method described how to do it in AS3 the AS2 way.

I find it a little absurd, to be honest, to go to such lengths, only to avoid a second file, but to each his own