Preloading External .swfs

I’m looking for a peice of actionscript which will give me a load-bar preloader for an externally loaded .swf file. I’m not great with actionscript (though not totally out of it.) and am currently using the :

if (_framesloaded>=_totalframes) {
gotoAndPlay(3);
} else {
gotoAndPlay(1);
}

approach, which doesn’t give me a loadbar. When I tried to use the loadbar like this:

bytes_loaded = Math.round(_root.getBytesLoaded());
bytes_total = Math.round(_root.getBytesTotal());
getPercent = bytes_loaded/bytes_total;
_root.loadBar._width = getPercent100;
_root.loadText = Math.round(getPercent
100)+"%";
if (bytes_loaded == bytes_total) {
_root.gotoAndStop(3);
}

(and with a “gotoAndPlay(1);” in the next frame)

it failed to work for both the regular movies within MX 2004 as well as the externally loaded ones. I know there’s an easy fix here…I just don’t know what it is.

Where did you place your code? If your loading your external SWF into a movieclip the code should go on the movieclip itself. Here’s an example of an easy preloader I’ve done before:


onClipEvent(load){
	total = _parent.getBytesTotal();
}

onClipEvent(enterFrame){
	current = _parent.getBytesLoaded();
	percent = Math.floor((current/total)*100);
	_xscale = percent;
	updateAfterEvent();
	trace(percent);
	_parent.loadPercent = percent+"%";

	if (percent >= 100){
		_xscale = 100;
		_parent.gotoAndPlay(2);
	}
}