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); } }
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.
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
if(percent>99) I have also seen problems with this in the past. You would be safer to use if(percent>=100)
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
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.
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
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.
Don't see what you're looking for? Try a search.
|