DJSK
May 19, 2008, 1:24am
1
I cannot get a preloader to work with loadVars when I load an external swf into my main time line. I don’t know what’s going on. I just can’t seem to get a value in my dynamic text field [COLOR=“Red”]loadText[/COLOR] to show up. I have tried tracing but I keep getting a value of NaN. I can’t get the [COLOR=“red”]loadBar[/COLOR] to animate in either. Here is my code:
var libLoader:LoadVars = new LoadVars();
libLoader.load (“external.swf”);
bytes_loaded = Math.round(libLoader.getBytesLoaded());
bytes_total = Math.round(libLoader.getBytesTotal());
getPercent = bytes_loaded/bytes_total;
this.loadBar._width = getPercent100;
this.loadText = Math.round(getPercent 100)+"%";
libLoader.onLoad = function() {
gotoAndPlay(2);
}
why are you using LoadVars for swf. Use this class instead.
var container:MovieClip = this.createEmptyMovieClip("container",
this.getNextHighestDepth());
var image:MovieClip = container.createEmptyMovieClip("image",
container.getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number,
bytesTotal:Number):Void {
trace(target + ".onLoadProgress with " + bytesLoaded + " bytes of " +
bytesTotal);
}
mcLoader.addListener(listener);
mcLoader.loadClip("http://www.w3.org/Icons/w3c_main.png", image);
var interval:Object = new Object();
interval.id = setInterval(checkProgress, 100, mcLoader, image, interval);
function checkProgress(mcLoader:MovieClipLoader, image:MovieClip,
interval:Object):Void {
trace(">> checking progress now with : " + interval.id);
var progress:Object = mcLoader.getProgress(image);
trace("bytesLoaded: " + progress.bytesLoaded + " bytesTotal: " +
progress.bytesTotal);
if(progress.bytesLoaded == progress.bytesTotal) {
clearInterval(interval.id);
}
}
From Live Docs.
MovieClipLoader is probably the best way to load non-text data.(like JPG, PNG, SWF, GIF’s- that all i can think of)