Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ultimate Loading Loop (With % couter and bytes loaded)

Awesome Actions!

Ultimate Loading Loop (With % couter and bytes loaded)

by  Gasbag  Posted    (Edited  )
OK here goes :)

Create a Layer called "actions".
(Make that a habit. You don't have to do it, but it will be a mess if you don't.)

Then, call the first keyframe "start" (or sumtin') you can do your initialisation code there.
In the SECOND keyframe put this code:

Code:
    if (_framesloaded==_totalframes) {
        gotoAndStop ("main");
    } else {
        if (_framesloaded>=3) {
            loadMovie ("mylogo.swf", "moviedummy");
            gotoAndPlay ("loop");
        } else {
            gotoAndPlay ("start");
        }
    }

It will make sure that, if the movie is already in cache, it will not go into the loading loop again
The second if statement makes sure that if even the loadingloop isn't loaded yet, it will loop an empty frame.
The loadmovie statement loads an additional movie into the current scene, for ecxample your logo. (re-use! yay!)
For that to work, the movie must contain (preferably in another layer :) an empty dummy movie called "moviedummy" or sumtin'

Create 3 text-labels in another layer than "actions". They have to exist in frame 3 & 4! Frame 4 of this layer must not be a KEYframe.
In the 'Text options' toolbox, (Window->Panels->Text Options) set the textbox type to 'Dynamic text' for all three textboxes!
Name them "txt_numBytesLoaded", "txt_numBytesRemain" and "txt_procent". These names go into the 'Variable:' field of the textbox!

Label the 3rd keyframe "load", and put the following code:

Code:
    if (_framesloaded == _totalframes) {

        // Comment: the loadbar is explained later...
        loadbar.gotoAndStop("fullbar");
        gotoAndStop ("ready");
    } else {
        txt_numBytesLoaded = this.getBytesLoaded() add " bytes loaded";
        txt_numBytesRemain = (this.getBytesTotal()-this.getBytesLoaded()) add " bytes remaining";
        tempProc = int((this.getBytesLoaded()/this.getBytesTotal())*100);
        txt_procent = tempProc add " procent loaded";
        loadbar.gotoAndStop(tmpProc);
    }

This code updates the text labels so they will show the progress of the loading. Flash's function names speak for itself, don't they? :)
If all the frames are loaded, the movie jumps to a frame called "ready".

In the 4th keyframe put:

Code:
    gotoAndPlay ("load");

Then Flash will loop frame 3 & 4 until the movie is loaded.

Finally, label frame 5 "ready" and put your main movie there.

If you really want to outdo yourself, make an empty dummy movie in a layer that spans frame 3 & 4, and call it "loadbar".
Make this movie 101 frames long, and call frame 101 (the last frame (oh doh!) :) "fullbar". (Don't forget the actions layer!)
Put the code "Stop()" in the first frame.
In the remaining 100 frames you can make a movie that displays the progress of the loading.
For instance, a bar that changes color from red (not loaded, frame 1) to green (loaded, frame 100) in a shapetween.
Be sure to not OVERdo yourself. It is, after all, a LOADING movie, not the content you intended to show in and after the main frame.
Let your imagination run free, and let me know what you've made (i'd like to see my tutorials used :)

Oh yeah, one more thing, if you 'debug' this in flash, many loading / bytes things won't work.
You have to upload it to a webserver to see the final result. Hope you have a slow enough connection :) Cheers!

Gasbag-->

Gasbag's Gas-of-the-Day:
i have an example. ask me for it :)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top