# How can i play an external movie only if it is loaded

**URL:** <https://forum.kirupa.com/t/how-can-i-play-an-external-movie-only-if-it-is-loaded/21507>\
**Category:** Uncategorized\
**Created:** [May 22, 2003, 12:35pm UTC](https://forum.kirupa.com/t/how-can-i-play-an-external-movie-only-if-it-is-loaded/21507 "2003-05-22T12:35:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oddin](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@oddin](https://forum.kirupa.com/u/oddin)\
**Post date:** [May 22, 2003, 12:35pm UTC](https://forum.kirupa.com/t/how-can-i-play-an-external-movie-only-if-it-is-loaded/21507/1 "2003-05-22T12:35:16Z")

</div>

the thing is like this.I have 2 swf files which are loaded in the main swf.How can i make a preloader for them inside the main swf to display how much of the other swf has been loaded?Without adding a second scene…I was thinking about a dynamic text field that should display how much has been loaded for each movie.Unfortunately i don’t know how to da that.I have tried the code like this but it doesn’t work:  
per\_fractal = Math.Floor(getbytesloaded(fractal.swf)\*getbytestotal(fractal.swf)/100);  
Myoutput.text = “per\_fractal” + " %";

the script is like this:

but.onPress = function () {  
\_root.createEmptyMovieClip(“container”,1);  
loadMovie(“fractal.swf”,“container”);  
container.\_x = -50 ;  
container.\_y = 285.9;  
container.\_alpha = 0;

}

accel = container.\_alpha + 1/2;  
onEnterFrame = function() {  
container.\_alpha = container.\_alpha + accel;   
}

but2.onPress = function(){  
\_root.createEmptyMovieClip(“container”,1);  
loadMovie(“face.swf”,“container”);  
container.\_x = -50 ;  
container.\_y = 285.9;  
container.\_x = 170;  
container.\_y = 232;  
container.\_alpha = 0;  
}

---

<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:** [May 24, 2003, 5:58am UTC](https://forum.kirupa.com/t/how-can-i-play-an-external-movie-only-if-it-is-loaded/21507/2 "2003-05-24T05:58:24Z")

</div>

Ok … I haven’t tried this but now that I think about it, this should work:

1. In the movie you want to display a preloader for on the host swf, make two extra keyframes at the very beginning of the timeline (frame 1&2).

2. To the first keyframe, add a new mc (CTRL+F8, don’t forget to drag it from the library onto the stage after using CTRL+F8) and apply following code to it (to the mc that is, not the keyframe):

[AS]onClipEvent(enterFrame){  
\_root.extloaded = \_parent.getBytesLoaded();  
\_root.exttotal = \_parent.getBytesTotal();  
if (\_root.continue == true){  
gotoAndPlay(frametostartmovieat);  
}  
}[/AS]

1. To the second keyframe, add this as:

[AS]gotoAndPlay(1);[/AS]

1. Now for your host movie. I suggest you use a preloader from the tutorial here on kirupa. It’ll make it easier to understand what’s going on. Find it [here](http://www.kirupa.com/developer/mx/percentagepreloader.htm)When you’re done setting it up, replace the code with this:

[AS]getPercent = \_root.extloaded/\_root.exttotal;  
this.loadBar.\_width = getPercent_widthofyourloadbar;  
this.loadText = Math.round(getPercent_100)+" %":  
if (\_root.extloaded == \_root.exttotal){  
\_root.continue = true;  
this.gotoAndPlay(3);  
}[/AS]

That should do it. If it doesn’t, please pm or mail me and I will check to see what’s wrong.

---

<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:** [May 24, 2003, 8:03am UTC](https://forum.kirupa.com/t/how-can-i-play-an-external-movie-only-if-it-is-loaded/21507/3 "2003-05-24T08:03:34Z")

</div>

well,i don’t have time to see if it work right now couse i’m on my way home(after a long night at work) but i’ll try it first time in the morning.Anyway it’s quite easy to make it with keyframes but my problem is that i have made the movie in such a way that if i add keyframes my code will not work…  
thanks anyway
