I’m trying to preload an swf which has an embed swf source. But it doesn’t want to work. I tried the simple preloading, but the progress event only run after loading. Any idea?
public class MainShell extends MovieClip
{
[Embed(source = "Main.swf")]
public var cs:Class;
public var hsf8z42fdfd_as32:MovieClip;
public function MainShell()
{
addEventListener(Event.ADDED_TO_STAGE, initialize, false, 0, true);
}
private function initialize(e:Event) {
loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, error, false, 0, true);
loaderInfo.addEventListener(ProgressEvent.PROGRESS, progress, false, 0, true);
loaderInfo.addEventListener(Event.COMPLETE, loaded, false, 0, true);
}
private function progress(e:ProgressEvent) {
var done:Number = stage.loaderInfo.bytesLoaded;
var total:Number = stage.loaderInfo.bytesTotal;
var w:int = done / total * 100;
loading.TT.text = String(w);
}
private function loaded(e:Event) {
loading.parent.removeChild(loading);
hsf8z42fdfd_as32 = new cs();
hsf8z42fdfd_as32.addEventListener(Event.COMPLETE, onComplete);
}
private function error(e:IOErrorEvent):void{
trace("Error!");
}
public function onComplete(e:Event) {
addChild(hsf8z42fdfd_as32);
}
It seems that the progress function only runs once after the file actually loaded. The progress event should run while loading, then why it doesn’t?
You cannot pre load embed object. The concept of embed object is they are shipped with the container.
This is as if your MainShell contains the Main.swf.
That means that as soon as the class containing the embed object will be loaded (in memory) by the classloader you’ll have at the same time all its dependencies (including embed objects). And only after that the code inside is executed, that is why you can’t see the progress of the loading.
The content loader is for loading remote content from a server. With this you’ll see the progress of the HTTP GET request (if it is not yet in the browser cache).
If you want to display the loading progress bar and so on you must not use embed content.
HIH
M.