# % preloader with load bar

**URL:** <https://forum.kirupa.com/t/preloader-with-load-bar/63341>\
**Category:** flash\
**Created:** [September 5, 2004, 5:37pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341 "2004-09-05T17:37:21Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Turbonium](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@Turbonium](https://forum.kirupa.com/u/Turbonium)\
**Post date:** [September 5, 2004, 5:37pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/1 "2004-09-05T17:37:21Z")

</div>

I used [this](http://www.kirupa.com/developer/mx/percentagepreloader.htm) tutorial to make a load bar. It works fine when preloading, say, an image file in the 3rd frame. However, when I try to make it show the loading status of a frame with the following attributes, it falters:

- 3 buttons (play, pause, stop)
- an integrated audio clip (mp3) controlled by the 3 buttons

For some reason, the loadbar doesn’t work. It just displays a white block on the Web page the size of the .swf file, and remains that way until the file is loaded, and then displays frame 3 (the audio feature). It’s as if the load bar frames don’t exist.

I used the exact same file, but modified it so that I replaced the 3rd frame (the audio buttons and stuff) with a simple BMP image, and the loadbar works. So the problem lies with the 3rd audio frame I’m meaning to use.

Any ideas? I’m pretty new with Flash and can’t figure out a solution.

---

<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:** [September 5, 2004, 5:48pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/2 "2004-09-05T17:48:35Z")

</div>

attach the fla file and i’ll hav a look

---

<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:** [September 5, 2004, 7:18pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/3 "2004-09-05T19:18:36Z")

</div>

> [@Mad Flasher](#):
>
> attach the fla file and i’ll hav a look

It’s pretty big (1MB+), even without the audio file in the Library. I must be doing something else wrong, but anyhow, the file is here: [link](http://www.samaseysan.com/loadbar_audio.fla)

---

<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:** [September 5, 2004, 8:22pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/4 "2004-09-05T20:22:31Z")

</div>

I saw no one had responded. My apologies to Mad Flasher if you’re looking at it.

Try this:

Frame one:  
//

getPercent = Math.floor (\_root.getBytesLoaded() / \_root.getBytesTotal() \* 100);  
\_root.loadBar.\_xscale = getPercent;  
\_root.loadText = getPercent +"%";  
if (getPercent == 100) {  
gotoAndPlay(3);  
}  
//  
Frame two:  
gotoAndPlay(1);  
//  
Frame three:  
as 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:** [September 5, 2004, 10:26pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/5 "2004-09-05T22:26:56Z")

</div>

I’ll try it out, but here’s a little question I got in general about Flash: what does “\_root” refer to? I see it all the time.

**EDIT:** I tried it and it doesn’t seem to work.

I have lots of experience in intermediate to advanced Java, so I’ll understand it pretty easily I think if you explain it to me sort of briefly. I tried Googling for it but didn’t really get any answers.

---

<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:** [September 5, 2004, 10:32pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/6 "2004-09-05T22:32:36Z")

</div>

When you create a new movie, and you’re staring at the timeline. That’s the \_root timeline. If you add a movie to that timeline named myMovie, for example, then you would access properties of myMovie as \_root.myMovie. If you opened myMovie and dropped in yet another moview called myMovie2, you would access the properties of the new movie as \_root.myMovie.myMovie2.

---

<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:** [September 5, 2004, 10:42pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/7 "2004-09-05T22:42:12Z")

</div>

> [@kennyb](#):
>
> When you create a new movie, and you’re staring at the timeline. That’s the \_root timeline. If you add a movie to that timeline named myMovie, for example, then you would access properties of myMovie as \_root.myMovie. If you opened myMovie and dropped in yet another moview called myMovie2, you would access the properties of the new movie as \_root.myMovie.myMovie2.

The \_root explanation makes sense, thanks.

The AS you gave me for frame 1 has the following syntax errors:

Scene=Scene 1, Layer=actions, Frame=1: Line 4: Statement block must be terminated by ‘}’  
if (getPercent == 100) {

Scene=Scene 1, Layer=actions, Frame=1: Line 5: Syntax error.  
gotoAndPlay(3);

I have no clue what the heck it’s talking about. The code looks fine to me too. Could be why it’s not working though.

**EDIT (again):** Nevermind, I refreshed the Output window and there are no syntax errors.

---

<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:** [September 5, 2004, 10:55pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/8 "2004-09-05T22:55:08Z")

</div>

well, did you put the ending brace on it?

}?

---

<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:** [September 5, 2004, 10:55pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/9 "2004-09-05T22:55:45Z")

</div>

and with the gotoAndPlay, should it be \_root.gotoAndPlay(3) or are you playing some other timeline?

---

<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:** [September 6, 2004, 2:12am UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/10 "2004-09-06T02:12:20Z")

</div>

> [@maximum\_flash](#):
>
> well, did you put the ending brace on it?
> 
> }?

Yup.

The syntax errors were a false alarm though, no issue there anymore.

> [@maximum\_flash](#):
>
> and with the gotoAndPlay, should it be \_root.gotoAndPlay(3) or are you playing some other timeline?

I tried that too, doesn’t 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:** [September 6, 2004, 3:01am UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/11 "2004-09-06T03:01:25Z")

</div>

What exactly doesn’t 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:** [September 6, 2004, 3:41am UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/12 "2004-09-06T03:41:46Z")

</div>

Just like last time, you don’t see any load bar or anything while it loads. You get a white block on the browser while it loads, and when it does load, it goes straight to frame 3, as if frames 1 and 2 don’t exist.

And it only happens when I use those audio buttons and junk for frame 3. Using an image file or something arbitrary as content in frame 3, the load bar works.

It’s seriously weird.

---

<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:** [September 6, 2004, 4:03am UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/13 "2004-09-06T04:03:36Z")

</div>

It looks like your trying to preload sound objects using the attach sound method, which will not work the way you’re trying to do it. Sound objects are exported on frame one (regardless of where they are declared). And, they are exported before your preloader code.

So, the solution is to save your sound objects are swf’s and preload those swf’s. To do this, define your sound objects in an new movie that will contain nothing but your sound objects. Define them like this:

music = new Sound(this);  
music.attachSound(“audio”);

The word “this” is key. Create the swf.

Then, in your main movie, use loadMovie to load them into an empty mc. For example,

\_root.musicHolder.loadMovie(“myAudio.swf”);

Then, preload the mc musicHolder like:

getPercent = Math.floor (\_root.musicHolder.getBytesLoaded() / \_root.musicHolder.getBytesTotal() \* 100);

Then, when you want to play the sound, use:

\_root.musicHolder.music.start();

---

<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:** [September 6, 2004, 5:12pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/14 "2004-09-06T17:12:56Z")

</div>

Sounds like it will work. I’ll try it out later, thanks.

---

<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:** [September 6, 2004, 6:19pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/15 "2004-09-06T18:19:11Z")

</div>

What does “NaN” stand for?

I’m getting a little glitch where the loadbar starts off at full, and the percentage reading is “NaN” (when truncated with the “%”, it’s “NaN%”).

I’m guessing it means something like “null”.

---

<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:** [September 6, 2004, 6:19pm UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/16 "2004-09-06T18:19:49Z")

</div>

Not a number.

---

<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:** [September 11, 2004, 5:24am UTC](https://forum.kirupa.com/t/preloader-with-load-bar/63341/17 "2004-09-11T05:24:46Z")

</div>

it means not a number. the value your getting is, for some reason, not being read as a number by flash.
