% preloader with load bar

I used this 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.

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

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.

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.

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.

well, did you put the ending brace on it?

}?

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

Yup.

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

I tried that too, doesn’t work.

What exactly doesn’t work?

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.

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

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

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”.

Not a number.

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