# Preloading using on clip event?

**URL:** <https://forum.kirupa.com/t/preloading-using-on-clip-event/1010>\
**Category:** flash\
**Created:** [August 6, 2002, 12:31pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010 "2002-08-06T12:31:58Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![RageW0lf](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@RageW0lf](https://forum.kirupa.com/u/RageW0lf)\
**Post date:** [August 6, 2002, 12:31pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/1 "2002-08-06T12:31:58Z")

</div>

I am using loadmovie to load a separate .swf file into a movie clip which is on my main file time line.  
Is there anyway I can use Onclipevent () to preload the movie I am loading in?

(Iceman offered some code but I couldn’t get it to work)

---

<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 6, 2002, 5:38pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/2 "2002-08-06T17:38:36Z")

</div>

do you need to preload the movie in the main movie or the loaded one?:-\  
on the loaded on is easier…

---

<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 6, 2002, 7:48pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/3 "2002-08-06T19:48:32Z")

</div>

The problem I have is that on a slow connection 56K or slower, the sub-movies I am loading in can take seconds to appear. There is quite a large pause. Each has a preloader at the start of it.

Iceman said words to the effect of : you can eliminate the pause if the preloader for the sub-movies is on the main movie timeline attached to the movie clip I am loading the files into.

To simplify : I want the preloader for the sub-movies on the main timeline.

I hope that clarifys.

Any ideas?

---

<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 8, 2002, 6:32am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/4 "2002-08-08T06:32:59Z")

</div>

I’m after one of those too, one…

Anyone?

---

<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 8, 2002, 9:10am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/5 "2002-08-08T09:10:23Z")

</div>

I am currently 85% done with my new preloader experiment.

It is, in short, a preloader that works in conjunction with a function in the main movie. This in turn is called upon to preload any particular object in the movie.

It’s currently working, but has some bugs to be ironed out.

If I can figure out how to explain what it is that I’m doing, I’ll post that info here tomarrow. Might take me a little longer though. I sort of create as I go along… a bad way to do it for sure… it always takes me a couple of days to sort all of the stuff I created into anything comprehensible.

---

<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 8, 2002, 10:50pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/6 "2002-08-08T22:50:15Z")

</div>

\>\> this is frame actions of fr1 in main movie::

// Feb 6th, 2002  
// Sequential Preloader BETA 2 by Jesse Stratford  
// [www.actionscript.org](http://www.actionscript.org), [jesse@actionscript.org](mailto:jesse@actionscript.org)  
// --------------------------  
// initialize counter variables  
count = 0;  
// how many movies are we going to be loading?  
numMoviesToLoad = 2;  
// define our loadNext function  
function loadNext () {  
// we’re no longer preloading the last movie  
\_root[“loadcontainer”+count] = false;  
// send the percent bar back to it’s first frame (0%)  
\_root.bar.gotoAndStop(1);  
// if there are still movies which need loading  
if (count\<numMoviesToLoad) {  
// incriment counter  
count++;  
// instance name for the next container MC  
var newName = “container”+count;  
// duplicate the container MC  
\_root.container.duplicateMovieClip(newName, count);  
// this is my debugging code  
with (this[newName]) {  
\_x = random(150);  
\_y = random(150);  
\_xscale = random(100);  
\_yscale = random(100);  
\_alpha = 50;  
}  
// end debugging  
// load the next movie in the sequence into the new container  
loadMovie (“phase”+count+".swf", \_root[newName]);  
// we are now preloading a new movie, set the var to True  
\_root[“load”+newName] = true;  
}  
}  
loadNext();

\>\> then, this is the obk=ject actions on a blank mC called container::  
onClipEvent (enterFrame) {  
// if this movie needs preloading  
if (\_root[“load”+this.\_name]) {  
// has the loadMovie command been processed yet?  
if (total\_bytes == null) {  
total\_bytes = this.getBytesTotal();  
} else {  
// controll bar - standard % preloader code  
loaded\_bytes = this.getBytesLoaded();  
remaining\_bytes = total\_bytes-loaded\_bytes;  
percent\_done = int((loaded\_bytes/total\_bytes)\*100);  
\_root.bar.gotoAndStop(percent\_done);  
// if loading is complete  
if (percent\_done == 100) {  
trace (“fully loaded”);  
// not loading this one any more, load the next  
\_root[“load”+this.\_name] = false;  
\_root.loadNext();  
}  
}  
}  
}

::: It all works really wellexcept I can’t get the actual preload displays happening (percent\_done, etc.)…

…Edge of my seat…

---

<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 8, 2002, 11:15pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/7 "2002-08-08T23:15:57Z")

</div>

Interesting. Thanks for the code, I’ll have to break that down to see what’s going on exactly.

Mine is far less extensive in it’s coding, that’s for sure. I do however do an “estimated time remaining for download”, which is nice.

---

<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 9, 2002, 2:19am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/8 "2002-08-09T02:19:34Z")

</div>

It should look like this: [www.actionscript.org/showMovie.php?id=355](http://www.actionscript.org/showMovie.php?id=355) The source files are also here…

Basically, you set the number of movies to load, make sure there are some phase1.swf’s, etc., then the function loadNext loads them all into blank mC’s, whilst also doing the % preloading thing.

Works REALLY well, but on my machine (using MX) the % preloading stuff doesn’t seem to work; nor can I seem to get it to work. Dang.

---

<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 9, 2002, 3:51am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/9 "2002-08-09T03:51:55Z")

</div>

Sorry I downloaded your .fla and I found the problem I didn’t relize that you were using flash 5 so I just changed a few lines. I have an .fla for your that solved your problem, if you give me your e-mail I can send it to you.  
Code:

onClipEvent (enterFrame) {  
if (total\_bytes == undefined) {  
total\_bytes = this.getBytesTotal();  
}  
loaded\_bytes = this.getBytesLoaded();  
remaining\_bytes = total\_bytes-loaded\_bytes;  
percent\_done = int((loaded\_bytes/total\_bytes)\*100);  
\_root.outputfield = percent\_done;  
}  
Try using this. Hope this helps. Sorry if it didn’t work before.

Kyle  
🙂

---

<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 9, 2002, 10:16am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/10 "2002-08-09T10:16:38Z")

</div>

ok thanks for downloading the .fla, my email is [tcarling@yahoo.com](mailto:tcarling@yahoo.com) :bandit:

---

<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 9, 2002, 11:13am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/11 "2002-08-09T11:13:18Z")

</div>

I must admit that’s pretty sweet.

I definitely have to break that down before I fully release my final master preloader clip. In my version you have to call out to whatever is being preloaded, but I think I’d like to have each in a que so that it just continues to load each as it can.

Good coding.

---

<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 9, 2002, 4:55pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/12 "2002-08-09T16:55:28Z")

</div>

thanks

Kyle:)

---

<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 10, 2002, 1:27pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/13 "2002-08-10T13:27:05Z")

</div>

thanks for your email and the code Kyle, unfortunately it didn’t preload my movie, it just went ahead and played - even when not fully loaded. Also it showed the numbers ontop of my movie my movie.

I alterred the code alittle to try and sort that problem out :

```php
onClipEvent (enterFrame) {
    if (this.getBytesTotal() == undefined) {
        total_bytes = this.getBytesTotal();
    } else {
        loaded_bytes = this.getBytesLoaded();
        percent = int(this.getBytesLoaded()/this.getBytesTotal()*100);
        _root.bar._xscale = percent;
        _root.outputfield = int(this.getBytesLoaded()/this.getBytesTotal()*100);
    }
}
onClipEvent (enterFrame) {
    if (_root.outputfield == 100) {
        _root.outputfield = " ";
    }
}

```

Then at the start of the movie I was loading in:

```php

if (_root.outputfield== " "){
gotoAndPlay 3;
}

```

in frame 2 I had a command gotoAndPlay 1.

although slightly messy, this coding did work.

However, a new problem arises 🙂

If my movie is loading in, and it gets to eg. 20 and you press another button (or the same button) it shows the number it got to, in this case 20 for a couple of seconds, then jumps back to counting from 0 again. It looks Bizzarre!

so is there anyway I can set \_root.outputfield to show nothing (blank) each time I click a button? (I’ve tried a couple of ways neither worked).

also, less importantly, my coding there is a bit messy there - Is there anyway to just alter the code attached to the instance of the clip I am loading into to a) make the number dissapear, and b)stop the movie playing until all 100% is loaded in? I tried and If statement it just seemed to ignore it though :-\

also a question about the \_root.bar command. The x\_scale make me think this is a loading bar that increases in horizontal size as it loads in. If I had a graphic symbol on the timeline called .bar would it increase in size, if not how would I make the loading bar work?

the example is the “able grafix” button of [http://www.Innovati0n.com/portfoliotest.html](http://www.Innovati0n.com/portfoliotest.html)

---

<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, 2002, 1:35am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/14 "2002-08-11T01:35:10Z")

</div>

e-mail me your .fla, [iceman4@sympatico.ca](mailto:iceman4@sympatico.ca)

Kyle:)

---

<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, 2002, 6:51am UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/15 "2002-08-11T06:51:17Z")

</div>

I suggest that anyone interested in this subject visit Moock’s link, here.

> **[Design ideas and resources.](https://www.oreilly.com/topics/design)**
>
> Insights, ideas, and tools for designing the future.

Though I love my work on the preloader… moock is the master. Read his words.

---

<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 14, 2002, 9:52pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/16 "2002-08-14T21:52:00Z")

</div>

Thanks to all that posted I got it working how I wanted in the end 🙂

Special thanks to Kyle (Iceman) - thanks for all your help.

[http://www.Innovati0n.com/portfolio.html](http://www.Innovati0n.com/portfolio.html)

---

<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 14, 2002, 11:12pm UTC](https://forum.kirupa.com/t/preloading-using-on-clip-event/1010/17 "2002-08-14T23:12:08Z")

</div>

Hey RageWolf,

Your welcome and the site looks good, I’m glad I could help, if you need help again or anything just e-mail me. By the way I forgot to metion that I really like the design of your site, I like the transitions after the buttons are clicked they’re very “innovative”.

Good luck with the site

Kyle:)
