Ok, step 1
- go to the scene palet and creat a new scene. Name it "preload"
- on the first frame, layer 1 of this scene, you will want to place whatever graphics and/or text you wish people to see while your movie loads up. For the sake of this tutorial just type the words "movie loading" and center it on the stage. Extend this text for three frames (place cursor on frame three and press F5).
- now create a second layer. Name this layer "actions" and create an empty keyframe on frame two (you can create an empty keyframe by clicking in frame two and pressing F7)
- open the actions palet and place the following code
- "var total" is a variable you have created which holds the total number of bytes in the movie
- "var loaded" hold the total numbery of bytes which have loaded thus far.
- the "if" statement looks to see if the number of loaded bytes equals the total number of bytes in the movie. If they are equal then the timeline is told to go to and play the first frame of the next scene. In this example my next scene is called "intro" (change "intro" to reflect the name of your next scene).
var total = _root.getBytesTotal();
var loaded =_root.getBytesLoaded();
if (loaded>=total) {
gotoAndPlay("intro", 1);
} - now create another blank keyframe in frame three of the "actions"
layer. Place the following code in the actions palet.
gotoAndPlay(1); - if the script in frame two determines that the movie has not been loaded yet, the timeline will continue on to frame three. Here we want to send the timeline back to the beginning so it will loop over and over until the movie has loaded.
Step 2
- create a new layer and name it "bar". In frame one create a long bar on the stage using the rectangle tool. Extend this image accross all three frames (F5).
- now, select the bar and press (F8) to turn the bar into a symbol. Choose movie clip and name it "loadbar". Now name the movie clip instance "loadbar" (without quotes) in the properties inspector.
double click "loadbar" so that you are working on the "loadbar" timeline. On frame one choose the setProperty action.You will see three entry options Property, Target and Value.
Property: from the drop down choose _xscale (X scale factor)
Target: type in "this" without quotes. and check
the expression box to the right.
Value: type in the following code (_root.getBytesLoaded()/(_root.getBytesTotal()))*100
then check the expression box to the right.
-
this code divides the number of bytes loaded by the total number of bytes in the movie then multiplies that by 100 to give us a percentage. That percentage is then used to change the size of the MC relative to the bytes loaded.
Your final code should look like this:
| setProperty(this, _xscale, (_root.getBytesLoaded()/(_root.getBytesTotal()))*100); |
Now extend (using F5) the timeline to frame two! (you must do this to make the action repeat istself). This allows the timeline to loop.
Now double click your loading bar (or edit symbol from library) and move the rectangle so that the registration point (the white dot in the middle) is positioned on the left hand edge of the rectangle, this will make your bar grow to the right rather than in both directions from the middle. You may have to reposition your bar on the main timeline after doing this.
Note:
If you do not wish to load the entire movie before the user is let into the first scene you must divide the total number of bytes in the movie by some number. In other words, if I wanted only half the movie to load first, I would divide the total number of bytes in the movie by "2" as shown below. (one third of the movie would be "3" , one quarter of the movie would be "4" , etc.)
| var total = _root.getBytesTotal()/2; var loaded =_root.getBytesLoaded(); if (loaded>=total) { gotoAndPlay("intro", 1); } |
when you choose to load only part of the movie you must also make the same change inside the "loaderbar" MC so that the loading bar acurately represents how much of the preload has loaded.
| setProperty(this, _xscale, (_root.getBytesLoaded()/(_root.getBytesTotal()/2))*100); |





