A Flash Developer Resource Site

Page 1 of 3 123 LastLast
Results 1 to 20 of 53

Thread: Preloader Explained

  1. #1
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554

    Preloader Explained

    Ok i have seen about 5000 posts asking about how to make a preloader
    and how it works. Within this post i will describe how the preloader
    works, and how to use it.A preloader is something that holds the
    movies playhead at the first frame or specified frame until the
    total file size of the movie is loaded, if a preloader is not used
    in your movie, the movie can become choopy and unclear whihc can
    ruin the entire movie, making a preloader essential to understand.
    First off download the attached fla. Once you have it opened as you
    can see the entire preloader is inside 1 movieclip making this a
    very simple object to use. In your preloader you can have any amount
    of animations you like, but keep in mind that the preloader can't
    preload its self, so the preloader must be loaded before the
    preloader can start to work. You might want to keep the preloader
    size under 10 kb. Next open the preloader movieclip by double
    clicking on the preloader and you will see multiple layers with
    various things on them. We are going in order from top layer to
    bottom layer. In the first layer is the actions
    code:

    _root.stop();
    PercentLoaded = _root.getBytesLoaded()/_root.getBytesTotal()*100;
    if (PercentLoaded != 100) {
    setProperty(bar, _xscale, PercentLoaded);
    } else {
    _root.play();
    }
    percentDone = Math.ceil(PercentLoaded)+"%";
    bytesloaded = (_root.getBytesLoaded()/1000);
    bytestotal = (_root.getBytesTotal()/1000);
    bytes_loaded = Math.ceil(bytesloaded)+"kb";
    bytes_total = Math.ceil(bytestotal)+"kb";


    I will describe these as we get to each part. In the second layer is
    just an outline of the load bar so you can see how far the loading
    has left(this part is optional).In the third layer is the loadbar
    it's self which is what changes size as you can see by these actions
    code:

    _root.stop();
    PercentLoaded = _root.getBytesLoaded()/_root.getBytesTotal()*100;
    if (PercentLoaded != 100) {
    setProperty(bar, _xscale, PercentLoaded);
    } else {
    _root.play();
    }


    _root.stop(); stops the main playhead as i forgot to mention before
    the only content that should be on the first frame of oyu movie
    should be the preloader everything is at least 1 frame later. So
    when the playhead stops on frame 1 the movieclip on frame one(the
    preloader) loops and inside this movieclip is two frames which loop
    continually. On the second frame on the actions layer is
    code:

    gotoAndPlay(1);


    what this effectively does is sends the playhead that is inside the
    movieclip back to frame one and recalls the actions in that layer
    therefore updating all the actions every 2 frames. the PercentLoaded
    is a variable that is defined by the total amount of bytes in the
    swf, that is if oyu say _root.getBytesLoaded() because if you say
    getBytesLoaded you are basically saying get the bytes for just this
    movieclip and then it will only load hte preloader and the rest of
    the movie will still be unloaded. When you say _root.getBytesLoaded
    ()/_root.getBytesTotal() you are creating a ratio that will always
    be less than or equal to 1 which is how you find the percentage
    loaded. Lets say you have a movie that is 100kb and 25kb of it is
    loaded. The PercentLoaded would be .25 and if we want the actaul
    percent all of us mathmaticians know that you have to mulitply it by
    100 to get the actual percent, hence you have the PercentLoaded. Now
    in the next line of scripting where it says
    code:

    if (PercentLoaded != 100) {


    this is an if statement saying if the PercentLoaded variable is NOT
    equal to 100 then do the following actions. The following actions are
    code:

    setProperty(bar, _xscale, PercentLoaded);


    this sets the propertie of the loadbar which has an instance
    (reference name) of bar so we set the property of the _xscale of the
    bar which is 100 if it is equal to the regular _xscale making this a
    handy tool to use since it can be equivilant to the PercentLoaded.
    We could also say these actions in the one aboves place and it would
    do the same thing
    code:

    _root.preloader.bar._xscale = PercentLoaded;


    and now to the next line where it says
    code:

    }else{


    this is basically equivilant to saying if the if statement
    code:

    if (PercentLoaded != 100) {


    is not true then do the following actions which are
    code:

    _root.play();


    this is basically the opposite of the _root.stop(); action. What the
    _root.play(); action does is starts the main timeline playhead again
    so the movie continues to play. So here is what these actions
    code:

    } else {
    _root.play();
    }


    mean in regular terms: if the PercentLoaded is equal to 100 then
    play the main timeline. Pheww now to layer 4. In layer four is the
    display of the percent done. The way we display variables is create
    a dynamic text box and give it a var which you can relate so that it
    will display whatever you want it to say in actionscripting. In this
    case you could use the PercentLoaded varible like so
    code:

    percentDone = Math.ceil(PercentLoaded)+"%";


    what Math.ceil() does is it basically rounds the number following it
    to a whole number this also can be done with the Math.round()
    function. So we are rounding the PercentLoaded so that if the actual
    PercentLoaded was 54.67895634 it will display 55. When i say +"%" i
    am indicating that you need to add the following to the display.
    This just happens to be in quotations meaning that you add the
    character to that text field instead of a variable. Now on to layer
    5. In layer 5 is a dynamic text field that displays the kb loaded
    using these actions
    code:
     
    bytesloaded = (_root.getBytesLoaded()/1000);
    //this just assigns a variable the value of the bytes loaded *1000
    //since 1 kb is 1000 bytes
    bytes_loaded = Math.ceil(bytesloaded)+"kb";
    //the line above rounds the bytesloaded and adds the charaters kb to
    //it and assigns the text field bytes_loaded that value


    Also in layer 5 is just a regular text field with the value of "of"
    showing that this amount of kb is loaded out of this other amount of
    kb. And lastly in that layer is the other text field displaying the
    totalbytes
    code:

    bytestotal = (_root.getBytesTotal()/1000);
    //here we assign this variable getting the bytes of the total swf
    //which will not change but needs to be assigned
    bytes_total = Math.ceil(bytestotal)+"kb";
    //and the line above assigns the text field bytes_total the value
    //above


    In the last and final layer is a simple animation that loops whihc
    can be removed or changed and will not affect the loading process.
    I hope this tutorial has helped you and if you have any questions
    feel free to post back and ask. If you feel something should be
    added, please post as well and i will edit it.
    Thanks,
    Joe
    Last edited by joejoe2288; 07-28-2004 at 01:23 AM.
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  2. #2
    One day I will understand this
    Join Date
    Apr 2004
    Location
    Norman Oklahoma
    Posts
    142
    awesome... except for the text not wordwrapping

    I'm all for a 'sticky'

  3. #3
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    what is word wrapping i wasn't trying to make the animaiton look good i was just showing you can put as much into it as you want and a sticky would be pimp
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  4. #4
    One day I will understand this
    Join Date
    Apr 2004
    Location
    Norman Oklahoma
    Posts
    142
    I was just refering to the fact that looking at what is posted above... you have to scroll way to the right to see it all.

    Thats all.

  5. #5
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    there ye go
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  6. #6
    One day I will understand this
    Join Date
    Apr 2004
    Location
    Norman Oklahoma
    Posts
    142
    mucho better.

  7. #7
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554

    STICKY Please

    will somebody sticky this i just don't want to ever see another post about preloaders
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  8. #8
    Junior Member
    Join Date
    Jul 2002
    Posts
    9
    Excellent post.

    Very helpful and informative.

  9. #9
    One day I will understand this
    Join Date
    Apr 2004
    Location
    Norman Oklahoma
    Posts
    142
    another question... when loading a movie that has a lot of button presses that load more external movies... is there a way to have the opening preloader load all of the movies?

    is that possible? I'm not sure.

  10. #10
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    yes there is i forgot how to do it damnit i read a tutorial on it, it had a slang term like garabe traffic or something it wasn't that but yes there is a way
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  11. #11
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    check this i linked ya
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  12. #12
    Older Member jankratochvil's Avatar
    Join Date
    Nov 2001
    Location
    CZECH
    Posts
    977

    preloader component in 2004

    another question - exist in Fl. 2004 preloader component an how can i use it?

    Thanks

    Jan
    I like all FLASH fans, but my girl can't stand them.
    -------------------------------------------
    I am still learning
    Sorry for my stupid questions (sometimes) and bad English.

  13. #13
    Senior Member green_eye's Avatar
    Join Date
    Apr 2004
    Location
    Sarasota, Florida
    Posts
    1,496
    Iaskway explains it also:
    Visit his flash tutorial link inside his footer.

  14. #14
    Older Member jankratochvil's Avatar
    Join Date
    Nov 2001
    Location
    CZECH
    Posts
    977
    Where can i found this tutor?

    Jan

    Originally posted by green_eye
    Iaskway explains it also:
    Visit his flash tutorial link inside his footer.
    I like all FLASH fans, but my girl can't stand them.
    -------------------------------------------
    I am still learning
    Sorry for my stupid questions (sometimes) and bad English.

  15. #15
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  16. #16
    Older Member jankratochvil's Avatar
    Join Date
    Nov 2001
    Location
    CZECH
    Posts
    977
    Sorry this is not what i mean

    http://www.flashbax.com/flash_preloaders.htm

    It describes preloader code, but i thought using component in Fl. 2004

    Jan


    Originally posted by joejoe2288
    http://www.flashbax.com
    I like all FLASH fans, but my girl can't stand them.
    -------------------------------------------
    I am still learning
    Sorry for my stupid questions (sometimes) and bad English.

  17. #17
    Who, What, Why ... ? Fraggs's Avatar
    Join Date
    Jul 2003
    Location
    Flashland .. where else ?
    Posts
    786
    If you mean how do you incorporate the flash mx 2004 preloader component into your movie, I beleive you just ddrag and drop it into your movie and it sorts itself out with all the relevant coding etc.

    Regards,

  18. #18
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    why use components when you can make customizables ones of your own that look much cooler eg not my example lol
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  19. #19
    Who, What, Why ... ? Fraggs's Avatar
    Join Date
    Jul 2003
    Location
    Flashland .. where else ?
    Posts
    786
    Meh, I must admit I prefer to make my own, but, if your not to sure what it is your doing with the scripting the the loader component is a good place to start as it gives you a working example and a customizable base.

    Regards,

  20. #20
    Older Member jankratochvil's Avatar
    Join Date
    Nov 2001
    Location
    CZECH
    Posts
    977
    i tried it so but how can i set up code for preloading.


    The component is not displaying loaded content
    I like all FLASH fans, but my girl can't stand them.
    -------------------------------------------
    I am still learning
    Sorry for my stupid questions (sometimes) and bad English.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center