Be a Supporter!

Animated Preloader? (AS2)

  • 769 Views
  • 6 Replies
New Topic Respond to this Topic
DahDoctow
DahDoctow
  • Member since: Mar. 11, 2010
  • Offline.
Forum Stats
Member
Level 11
Game Developer
Animated Preloader? (AS2) Aug. 27th, 2011 @ 01:26 PM Reply

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

DahDoctow
DahDoctow
  • Member since: Mar. 11, 2010
  • Offline.
Forum Stats
Member
Level 11
Game Developer
Response to Animated Preloader? (AS2) Aug. 27th, 2011 @ 01:30 PM Reply

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

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Animated Preloader? (AS2) Aug. 27th, 2011 @ 01:44 PM Reply

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


}
DahDoctow
DahDoctow
  • Member since: Mar. 11, 2010
  • Offline.
Forum Stats
Member
Level 11
Game Developer
Response to Animated Preloader? (AS2) Aug. 28th, 2011 @ 09:50 PM Reply

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

boney-man
boney-man
  • Member since: Jul. 24, 2005
  • Offline.
Forum Stats
Member
Level 11
Musician
Response to Animated Preloader? (AS2) Aug. 29th, 2011 @ 12:42 AM Reply

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
DahDoctow
DahDoctow
  • Member since: Mar. 11, 2010
  • Offline.
Forum Stats
Member
Level 11
Game Developer
Response to Animated Preloader? (AS2) Aug. 29th, 2011 @ 06:24 PM Reply

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

boney-man
boney-man
  • Member since: Jul. 24, 2005
  • Offline.
Forum Stats
Member
Level 11
Musician
Response to Animated Preloader? (AS2) Aug. 30th, 2011 @ 01:38 PM Reply

Yay!


#1286129 // soundcloud.com/1shibumi

BBS Signature