00:00
00:00
Newgrounds Background Image Theme

OPREA just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Animated Preloader? (AS2)

1,173 Views | 6 Replies
New Topic Respond to this Topic

Animated Preloader? (AS2) 2011-08-27 13:26:35


Hello, I am making an animated preload in AS2.

I have made 100 frames, and each frame does something different. I am no programmer, but I was wondering if there was a code to make it so that each percent that goes up, the animation would continue.

Please help me out, I'm trying to make the best preloader ever!

Here is my code:

This code is on the main timeline, not inside the movieclip
stop();
onLoad = function() {
total = _root.getBytesTotal()
loaded = 0
}
loading_bar.onEnterFrame = function() {
loaded = _root.getBytesLoaded()
loading_bar.gotoAndStop(percent);
percent = loaded/total*100

}
The movieclip which contains the animation is the instance of loading_bar.


What's it gonna be? You have to decide.

Tits, or destiny...

...Tits...

Response to Animated Preloader? (AS2) 2011-08-27 13:30:27


Ah, crap. Forgot to mention what is wrong with my code.

Well, the animated preloader is basically stuck at 1% until it finished loading, then it just goes straight to the play button. Nothing between 1 and 100...


What's it gonna be? You have to decide.

Tits, or destiny...

...Tits...

Response to Animated Preloader? (AS2) 2011-08-27 13:44:10


"percent" is probably undefined when you're telling the bar to go to and stop.

Switch around the order of the code. It should work.

top();
onLoad = function() {
total = _root.getBytesTotal()
loaded = 0
}
loading_bar.onEnterFrame = function() {
loaded = _root.getBytesLoaded()

percent = loaded/total*100

loading_bar.gotoAndStop(percent);


}

Response to Animated Preloader? (AS2) 2011-08-28 21:50:17


Alright, it is still doing the same thing.

Also, inside the preloader symbol on the timeline I have a stop(); command on every frame. Dunno if this is the cause, but whenever I ree this stop(); command it just keeps looping the preloader until it is loaded.


What's it gonna be? You have to decide.

Tits, or destiny...

...Tits...

Response to Animated Preloader? (AS2) 2011-08-29 00:42:23


At 8/27/11 01:26 PM, StompRocket2009 wrote: This code is on the main timeline, not inside the movieclip
stop();
onLoad = function() {
total = _root.getBytesTotal()
loaded = 0
}
loading_bar.onEnterFrame = function() {
loaded = _root.getBytesLoaded()
loading_bar.gotoAndStop(percent);
percent = loaded/total*100

}

Well first of all I see a bunch of missing semicolons but since you're not getting an error for that, it's not the problem. Like 4urentertainment said, I'd put the line defining percent before the line that tells the movie clip which frame to go to, but since that's apparently also not the problem all I can suggest is perhaps there's some sort of scope problem? Is "loaded" a variable that can be accessed from the loading_bar movieclip's onEnterFrame function? To avoid this you could either make loaded a global variable or reference it with _root.loaded or you could just take the onEnterFrame function off of loading_bar (because it doesn't need to be there) and make it

stop();
onLoad = function(){
total = _root.getBytesTotal();
loaded = 0;
}

onEnterFrame = function(){
loaded = _root.getBytesLoaded();
percent = Math.floor(loaded/total*100);
loading_bar.gotoAndStop(percent);
}

In fact, in the course of writing that, I think I found what the actual problem is - your "percent" variable is not an integer! You might be telling your movie clip to go to frame 51.124738 or something lol. So I just floored the percent to make it an integer, and then told the movie clip to go to that frame.


#1286129 // soundcloud.com/1shibumi

BBS Signature

Response to Animated Preloader? (AS2) 2011-08-29 18:24:49


Oh man, thank you! It is working now, and looks lovely C:


What's it gonna be? You have to decide.

Tits, or destiny...

...Tits...

Response to Animated Preloader? (AS2) 2011-08-30 13:38:49


Yay!


#1286129 // soundcloud.com/1shibumi

BBS Signature