Preloading in AS3 with Linked Items in your Library
In AS2 you could add all your library's linked items onto a frame that was never getting called to make sure they would preload correctly. You can no longer do this in AS3. In AS3 your linked items will still preload in frame 0 before your preloading code will be executed. I found two work a rounds in ActionScript 3. One way to do it is explained good at http://www.bit-101.com/blog/?p=946. This way is a little tricky, especially for beginners. You will have to use the [Frame] metadata tag.
The way I found that is easiest and fastest is to just have a blank swf that handles the preloading of your other swf. This way you make sure your preloader will show up before frame 0.
Put the following code into the first frame of the swf that is handling the preloading.
The way I found that is easiest and fastest is to just have a blank swf that handles the preloading of your other swf. This way you make sure your preloader will show up before frame 0.
Put the following code into the first frame of the swf that is handling the preloading.
stop();
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("mySWF.swf"));
function loop(e: progressEvent):void{
var perc:Number = Math.round(e.bytesLoaded*100 / e.bytesTotal);
mcLoader.txtPercent.text = perc + "%";
}
function done(e:Event):void{
l.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.removeEventListener(Event.COMPLETE, done);
removeChild(mcLoader);
addChild(l);
}
The only thing to be aware of is how to access you FlashVars and that the swf for the preloading is now your stage.



Good Idea
Reply to this
Cool,
This is some great information about preloading in AS3,
Thanks for bringing this up
Reply to this
Another good post here today. You are really offering great and challenging concepts in your new blog and I think it will be a great success. Keep up the great work and keep the good ideas coming.
Reply to this
Good work man..this is the great website I have seen so far...outstanding..
Reply to this