Ultrashock Forums > Flash > ActionScript
AS2 - Simple Preloader not Appearring

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
AS2 - Simple Preloader not Appearring
Old 2008-02-19

I have a simple preloader on my site. For some reason, it won't display until it's at about 70%. Does anyone know why? Here's the code:

stop();
total = this.getBytesTotal();
this.onEnterFrame = function() {
loaded = this.getBytesLoaded();
percentage = Math.round((loaded/total)*100);
progressBar._xscale = percentage;
progressBar._alpha = 100;
percentageRead = "Loading "+percentage+"%";
if (total == loaded) {
delete this.onEnterFrame;
gotoAndPlay("intro");
}
};
postbit arrow 9 comments | 1216 views postbit arrow Reply: with Quote   
Registered User
edub70 is offline
seperator
Posts: 15
2007-07-13
Age: 31
edub70 lives in United States
seperator

Ultrashock Member Comments:
Laveklint's Avatar Laveklint Laveklint is offline Laveklint lives in Sweden 4 Creative Assets 2008-02-19 #2 Old  
my guess is that you have this code in the firstframe of your movie and the movie may be xKB..
so before you will see the progress of you preloader you have to load a certain amount before it starts displaying you preloader.. make sense to you?

My advice is to have a movie which job is to load you content.

Setup up a new movie and make the preloader in that to load in you other movie.

code in your "loaderMovie":
ActionScript Code:
  1. //////////////// Create a "container" to hold your movie
  2. var container = this.createEmptyMovieClip("container", this.getNextHighestDepth());
  3. //////////////// MOVIECLIPLOADER
  4. var mcl = new MovieClipLoader();
  5. loadList = new Object();
  6. mcl.addListener(loadList);
  7. loadList.onLoadStart = function(targetMC) {
  8.    // setup your starting properties
  9.    container._alpha = 0;
  10. };
  11. loadList.onLoadProgress = function(targetMC, lBytes, tBytes) {
  12.    var percentage = Math.round((lBytes/tBytes)*100);
  13.    progressBar._xscale = percentage;
  14. };
  15. loadList.onLoadInit = function(targetMC) {
  16.    // what happens when it´s loaded
  17.    container._alpha = 100;
  18. };
  19. mcl.loadClip("yourMovie.swf","container");

let me know how it works out
Reply With Quote  
Laveklint's Avatar Laveklint Laveklint is offline Laveklint lives in Sweden 4 Creative Assets 2008-02-19 #3 Old  
opps forgot.
set up your x & y for the container
ActionScript Code:
  1. container._x = 0; // or other _x value
  2. container._y = 0; // or other _y value
  3.  
Reply With Quote  
mrpinc mrpinc is offline 2008-02-20 #4 Old  
The reason for this is because Flash must load the first frame (which your preloader) is on before it can display anything. If you go to your publish settings and actionscript options and change the settings 'Export classes to frame:' to 2. As well make sure any linkages you have set up are NOT checked to 'export to first frame' This is real important for any components you are using since otherwise they will not appear. www.gotoandlearn.com talks about all this in the tutorial on advanced preloaders.
Reply With Quote  
edub70 edub70 is offline edub70 lives in United States 2008-02-20 #5 Old  
Thanks for the help folks. I did what mrpinc suggested and now the preloader is appearing much sooner. Actually, it appears when it's at about 20 percent. It's still not appearing earlier because I have dynamic text that displays the percentage amount. That dynamic text has a font I'm embedding, which if I don't embed, the preloader appears instantly, but in the wrong font. I suppose there's no way around that?
Reply With Quote  
Laveklint's Avatar Laveklint Laveklint is offline Laveklint lives in Sweden 4 Creative Assets 2008-02-20 #6 Old  
yes there is a way around it.. if do you as I posted.
Setup a "mainLoadMovie" and load in your "contentMovie"
Reply With Quote  
Nutrox's Avatar Nutrox Nutrox is offline Super Moderator Nutrox lives in United Kingdom 17 Creative Assets 2008-02-21 #7 Old  
An article in my Ultrablog covers this issue: Problemo Preloaders - Part One

The code is AS3 but the rules apply to any Flash movie.
Reply With Quote  
edub70 edub70 is offline edub70 lives in United States 2008-02-22 #8 Old  
Hey Gregaz! Thanks for the help. You're right. The preloader shows right away. But I guess with every AS success there is in turn, a failure:

1. the preloader won't go away once it's complete. Should I load the main.swf on the second frame of the preloader movie or something else?

2. I designed the main.swf to have some keyframe animations at the start. However, when the loader is complete and the main.swf is loaded into the container, the animation at the beginning has already completed and it appears as it does after those keyframes. I take it this means the main.swf is actually being loaded before you see it, then running through the animations while the preloader loads, and then being displayed after the animations are complete. Make sense?

3. I have some dynamic text that displays the percentage, as well as a loader bar. The dynamic text now won't display a space character inbetween the word "loading" and the percentage. I've tried "percentageRead = "Loading"+" "+percentage;" and "percentageRead = "Loading "+percentage;" and neither seem to work. I don't know if that has anything to do with this code. Might be a font issue on my end.

Thanks for any help. This is great learning!
Reply With Quote  
Laveklint's Avatar Laveklint Laveklint is offline Laveklint lives in Sweden 4 Creative Assets 2008-02-23 #9 Old  
I´m in a hurry so this will be fast...
about the space between your % and loading.. set it up like this:
"percentageRead = " + percentage;
where "percentageRead" is the text displayed infront of the percatage.. you have to have:
("string = " + other value)
Ill take a look at the other thing later.. have to run..
Reply With Quote  
framesakaflames framesakaflames is offline framesakaflames lives in Spain 2009-07-17 #10 Old  
Hello there,

I'm also new to actionscript and i have had the same problem with the preloader in a very big/complex website I'm developing that has many scenes and timeline use.
I used the container exemplified here and it works [almost] perfectly.
The only problem is that when it reaches approximately 80% of preloading, it already starts playing the timeline of the MC I'm about to load/display.
This completely ruins the beginning of the website's first scene...

Any ideas how prevent the loaded MC from playing before the preloader actually loads/disappears, I'll be immensely grateful...

Thanx!
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: