Groups | Blog | Home
all groups > flash actionscript > july 2004 >

flash actionscript : Is my code for this preloader wrong?


Jake Lyman
7/11/2004 9:37:27 PM
Hello All,

Working on a preloader and using the code below. Should work as far as I can
tell. Problem is, nothing happens! Any ideas what I might be doing wrong? I
have this code attached to a movie clip that is on the first frame of my movie.

Thanks so much!

Jake



onClipEvent(enterFrame) {
loading=_parent.getBytesLoaded();
total=_parent.getBytesTotal();
percent-=(percent-((loading/total)*100))*.25;
per=int(percent);
percentage=per+"%"
loadBar._width=per;
if(percent>99) {
_parent.gotoAndPlay(2);
}
}
rlc5611
7/11/2004 9:41:11 PM
If you are usinf MX 2004, it won't work because you have not initialized your
variable "percent" and it is undefined so any calculation done with it results
in NaN. If you are using MX, it looks like it should work.
Jake Lyman
7/11/2004 9:41:22 PM
Sorry, should have included a bit more info. I have a stop(); action on frame
one and the main content of my movie begins on frame 2. The movie does not
advance to frame 2 upon the execution of the code above.

Thanks!

Jake
rlc5611
7/11/2004 9:43:24 PM
if(percent>99)

I have also seen problems with this in the past. You would be safer to use

if(percent>=100)

Jake Lyman
7/11/2004 9:44:33 PM
Thanks for your quick reply! I am using MX2004. This code worked fine when I
was using MX. So you've solved my problem! The problem is, I don't understand
the solution because I'm so new to this. So I need to figure out how to
initialize percent and define it? Can you give me a shove in the right
direction to take care of this?

Thanks so much!

Jake
rlc5611
7/11/2004 9:48:30 PM
One way would be

onClipEvent(enterFrame) {
if(not beenherebefore) {
percent=0;
beenherebefore = true;
}
loading=_parent.getBytesLoaded();
total=_parent.getBytesTotal();
percent-=(percent-((loading/total)*100))*.25;
per=int(percent);
percentage=per+"%"
loadBar._width=per; i
f(percent>99) { _parent.gotoAndPlay(2);
}
}

even though beenherebefore would also be undefined the first time in, it does
not give any error so the if statement will function correctly since undefined
<> true.

Jake Lyman
7/11/2004 10:03:57 PM
rlc5611!!

Woohoo! You fixed it! No big deal for you, huge for me. Thanks so much.
For future understanding on my part, when you said in an earlier post that I
had not initialized the variable "percent" and that it was undefined, is that
kind of one in the same? By using the line of code you gave me:

percent=0;

does that initialize AND define percent?

Thanks so much!

Jake
rlc5611
7/11/2004 11:00:31 PM
One of the big differences between MX and MX2004 is that any variable that has
not be declared or otherwise initialized in some way is undefined. MX and
earlier versions treated these variables like zeros or empty strings so that if
you tried to do something with it, you could generally do it. MX 2004 no longer
allows this. If you have a lot of files created in earlier versions, this can
be a pain and one not immediately obvious. For example, if you had a file made
in MX and save the file as MX 2004, it will still keep the publish setting for
Flash 6 unless you change it. So, even though the file is edited, saved and
published in MX 2004, it still published for the V6 player so undefined
variables are handled just as in MX. If you later decide you want to publish
for the V7 player, only then do compatibility issues begin to emerge.
AddThis Social Bookmark Button