Make Flash Loading load progress bar _flash as

Source: Internet
Author: User
Copy Code code as follows:

SWF Movies in the network can be downloaded while playing, because of the current network transmission constraints, for large-capacity films, this real-time playback is not ideal. To avoid embarrassing waiting for the audience, flash production staff often design a load (loading) of the screen, such as all the bytes of the movie downloaded to the local and then play, so as to ensure the quality of the movie playback. This paper introduces a standard method of loading production.


Steps:
1. Open the Flash MX 2004, select the Rectangle tool, and draw the next one in the home scene. Only the border has a rectangle, in this case the rectangle is 350*16 pixels.
2. Again in the home scene with a rectangular tool to draw a rectangle with only fill without a border, and press the F8 key to convert it to a movie clip (note: Its registration point must be selected at the left of the rectangle), its instance named bar. In this case, the rectangle size is 345*11 pixels.
3. The above two rectangles are arranged in the home scene so that the bounding rectangle is nested filled with rectangles.
4. Next to both rectangles, drag a dynamic text box with a type tool named Bar_per.

At this point, the preparation is ready, that is, the creation of two rectangular boxes and a dynamic text box, the following preparation of code.

5. In the home scene, a new layer, select the layer 1th frame, press F9 to open the Action Script editing window, enter the following code:

This.onload=function () {
Mybytestotal=_root.getbytestotal ();
}
This.onload ();
This.onenterframe=function () {
Mybytesloaded=_root.getbytesloaded ();
bar_xscale=mybytesloaded/mybytestotal*100;
Percent=math.round (Bar_xscale);
This.bar._xscale=bar_xscale;
this.bar_per=percent+ "%";

if (mybytesloaded==mybytestotal) {
Delete This.onenterframe;
_root.nextframe ();
}else{
This.stop ();
}
}
6. Make your Flash video from the main scene timeline from frame 2nd.

Annotations:


This.onload=function () {
Mybytestotal=_root.getbytestotal ();
}
This code refers to the total number of bytes of all elements present in the main timeline that are read and assigned to variable mybytestotal when the movie clip (in this case, the home view of the two rectangles and a dynamic text box) loads.

Ii

This.onload ();
Flash event handler function movieclip.onload=function () {...} A bit odd, where the code is set, if not followed by This.onload (), the code does not execute, so add this sentence so that the code can be executed.

Mybytesloaded=_root.getbytesloaded ()///reads the number of bytes loaded by all elements that exist in the main timeline and assigns them to the variable mybytesloaded.


bar_xscale=mybytesloaded/mybytestotal*100;//converts the mybytestotal to 100, the converted value obtained by mybytesloaded is assigned to the variable Bar_xscale, To assign the _xscale of bar in the main scene (the maximum value of the _xscale can only be 100), where the proportional calculation of elementary mathematics is used.


Percent=math.round (Bar_xscale);//Assign the value of the variable Bar_xscale to the variable percent so that the percentage shown is not fractional.

Expand:
1. "Download Speed" code design
① a dynamic text box with the appropriate width in the home scene with the text tool and set its variable name to rate.
② appends the following code before the This.onenterframe=function () {} code body if statement at the home scene code layer 1th frame:
T=gettimer ();
rate= "Download speed:" + math.round (mybytesloaded/t *)/100 + "k/s";

2. Code design for "time spent and remaining time"
① a dynamic text box with the appropriate width in the home scene with the text tool and set its variable name to Mytimes.
② appends the following code before the This.onenterframe=function () {} code body if statement at the home scene code layer 1th frame:

Timeloaded=math.round (t/1000);
Timeremain=math.round (timeloaded* (mybytestotal-mybytesloaded)/mybytesloaded);
Timeremain=math.round (TIMEREMAIN/60) + ":" +math.round (TIMEREMAIN%60);
Timeloaded=math.round (TIMELOADED/60) + ":" +math.round (TIMELOADED%60);
Mytimes= "has used time" +timeloaded+ "" + "remaining Time" +timeremain;
Note: If the "Download Speed" code is not designed, then the above code should append code T=gettimer ();
The whole code for the 1th frame of the rear scene code layer is expanded as follows:


This.onload=function () {
Mybytestotal=_root.getbytestotal ();
}
This.onload ();
This.onenterframe=function () {
Mybytesloaded=_root.getbytesloaded ();
bar_xscale=mybytesloaded/mybytestotal*100;
Percent=math.round (Bar_xscale);
This.bar._xscale=bar_xscale;
this.bar_per=percent+ "%";

T=gettimer ();
rate= "Download speed:" + math.round (mybytesloaded/t *)/100 + "k/s";

Timeloaded=math.round (t/1000);
Timeremain=math.round (timeloaded* (mybytestotal-mybytesloaded)/mybytesloaded);
Timeremain=math.round (TIMEREMAIN/60) + ":" +math.round (TIMEREMAIN%60);
Timeloaded=math.round (TIMELOADED/60) + ":" +math.round (TIMELOADED%60);
Mytimes= "has used time" +timeloaded+ "" + "remaining Time" +timeremain;

if (mybytesloaded==mybytestotal) {
Delete This.onenterframe;
_root.nextframe ();
}else{
This.stop ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.