# Preloading External .swfs

**URL:** https://forum.kirupa.com/t/preloading-external-swfs/60588
**Category:** flash
**Created:** [August 10, 2004, 11:49pm UTC](https://forum.kirupa.com/t/preloading-external-swfs/60588 "2004-08-10T23:49:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nlaffan](https://avatars.discourse-cdn.com/v4/letter/n/8491ac/32.png) [@nlaffan](https://forum.kirupa.com/u/nlaffan)
#### Post date: [August 10, 2004, 11:49pm UTC](https://forum.kirupa.com/t/preloading-external-swfs/60588/1 "2004-08-10T23:49:43Z")

</div>

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 = getPercent_100;  
\_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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 11, 2004, 5:45am UTC](https://forum.kirupa.com/t/preloading-external-swfs/60588/2 "2004-08-11T05:45:42Z")

</div>

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:

```auto

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);
	}
} 

```
