Mastering Flash Skills: Four cases of loading effect of pure ActionScript

Source: Internet
Author: User
Tags cos sin
Loading| tip: A slightly larger flash works will have a loading before playback, which takes into account the speed of the network, local browsing does not need to wait to download, but uploaded to the Internet, because each user's speed is different, So it is necessary to add loading images to our work, before, there are many tutorials on the loading method of production, today we give the reader four pure as loading effect, do not understand as rookie or "code blindness" can even directly copy the tutorial code into their own works , the friend who understands as code, can read the code carefully, learn more as knowledge, or derive more as loading effect. Thanks to the author = cotton Candy =, egg616, Lang provide source and train of thought--the leaf of the Flash guest Empire

A. = Loading course for cotton candy =


Relatively simple
Dynamically show load percent
Copy all the code to the first frame, and when the load is complete, it will start playing automatically.

Source:







BackgroundColor = 0x336699; Background color of text boxes





_y = Ordinate of stage.height/2;//text field













Two. One of the loading arts of egg616


1, the principle of production:
All the loading in the world can be divided into three parts:
1 Create a loop to update the data. Generally there are two methods, one is to make two frames, in the second frame with gotoAndPlay (1) command to generate a loop. The other is to do only one frame, using the onenterframe command to generate loops.
2 use Getbytestotal () and getbytesloaded () command to obtain file data.
3 Display the data obtained in the second step in a graphic or animated way (usually also in a textual manner)

The above explanation, to a will do loading person is very clear, but will not do the look probably or not (hehe) so below we step by step, do a simple example (do not do text display data):

2, a simple example (only two steps, I believe you have this patience):
Ⅰ open one of your favorite animations, create a new scene, and drag it to the front.
Ⅱ Add the following as action on the frame, that's it!

Source:










A function of drawing a line, four parameters corresponding to what, I see ha









Draw three horizontal lines to show download progress;











You can download the test two times ctrl+enter, if you have phobias, close your eyes and copy-paste it

The following is an illustration of the effect of this example



Three. egg616 's loading art of the second


1, open the animation you want to add loading, create a new scene, and drag it to the front.
2, add the following as code on the first frame of the front scene.

Source:

Copyright: Wujieching Guangdong Lianjiang
This work may be reproduced or modified at will, but please indicate the original author
Stop ();
SW = 550;
SH = 400;
//
Stage.showmenu = false;
Hide the Nasty right button menu
CS = 60;
How dense the grid is
R = 2550;
D = r/math.sqrt2;
The curvature of the grid
p = Math.PI;
Define constant PI
Createemptymovieclip ("ln", 1);
Ln.linestyle (0, 0XFFFFFF);
for (var i = 1; i<=cs; i++) {
Ln.moveto (Sw/2+r*math.cos (i/cs*p),-d+300+r*math.sin (i/cs*p));
Ln.lineto (Sw/2+r*math.cos (I/CS*P+P/2),
-d+300+r*math.sin (I/CS*P+P/2));
}
Let's draw a color gradient.
Createemptymovieclip ("BG", 0);
With (BG) {
colors = [0x6666ff, 0XFFFFFF, 0x660099];
Alphas = [30, 30, 80];
Ratios = [0, 100, 200];
LineStyle (5, 0x00ff00);
Matrix = {matrixtype: "box", x:200, y:115, w:50, h:450, R:P/2};
Begingradientfill ("linear", colors, alphas, ratios, matrix);

MoveTo ( -200-SW,-100);
LineTo (200+SW,-100);
LineTo (200+SW, 100+sh);
LineTo ( -200, 100+sh);
LineTo (-200,-100);
Endfill ();
}
//
R1 = 50;
r2 = 170;
Nu = 32;
3 parameters of the center circle respectively;
CR = 600;
CR is the fill radius
Createtextfield ("TE", 5, 75, 100, 160, 100);
Te.textcolor = 0x9900ff;
Create text to display downloaded data
function Fo1 (Nam, DE, RO) {
na = Createemptymovieclip (nam, de);
With (NA) {
_y = 40;
LineStyle (0, 0x000000, 0);
colors = [0x6666ff, 0XFFFFFF, 0x660099];
Alphas = [130, 130, 20];
Ratios = [0, 120, 200];
Matrix = {matrixtype: "box", X:-CR/2, Y:-CR/2, W:CR, H:CR, R:P/2};
Begingradientfill ("Radial", colors, alphas, ratios, matrix);
Here, use as to gradient the fill
MoveTo (r1, 0);
var bl = Math.Cos (P/NU);
for (var i = 1; i<=ro; i++) {
Curveto (R1*math.cos (i*p/(NU/2)-p/nu)/BL,
R1*math.sin (i*p/(NU/2)-p/nu)
/BL, R1*math.cos (i*p/(NU/2)), R1*math.sin (i*p/(NU/2)));
}
LineTo (R2*math.cos (ro*p/(NU/2)), R2*math.sin (ro*p/(NU/2)));
for (var i = ro; i>=1; i--) {
Curveto (R2*math.cos (i*p/(NU/2)-p/nu)/BL,
R2*math.sin (i*p/(NU/2)-p/nu)
/BL, R2*math.cos (i-1) *p/(NU/2)), R2*math.sin ((i-1) *p/(NU/2));
}
LineTo (r1, 0);
Endfill ();
}
}
This function is used to draw the middle circle in which the ring is made by the Curverto method,
This is not an introduction, and I will elaborate in the next tutorial
Onenterframe = function () {
AB = _root.getbytesloaded ();
bb = _root.getbytestotal ();
Get Data
SB = Int (AB/BB*NU);
Fo1 ("Di", 4, SB);
di._x = 275;
di._y = 200;
Di._yscale = 25;
Di._rotation =-30;
Call function as the ring above
Fo1 ("YZ", 3, SB);
Yz._xscale = 100*math.pow (3, 0.5)/2;
Yz._yscale = 25;
Yz._alpha = 30;
yz._x = 275;
yz._y = 360;
Make a transparent ring below, as the last Shadow
if (ab>>> "
di.onpress = function () {
Delete Onenterframe;
Te.removetextfield ();
Di.removemovieclip ();
Yz.removemovieclip ();
Ln.removemovieclip ();
Bg.removemovieclip ();
Play ();
};
}
};


Because it is pure as works, the FLA file is no longer available, the following is the effect map (jpg format, compared to the SWF is much worse.) )



Four. As Loading of the small Lang


1, open the animation you want to add loading, create a new scene, and drag it to the front.
2. Create a new empty MC and drag it into frame 1th of the new scene and name the instance: SS
3, in the MC add the following code (in other words: Click the MC, open as Panel, enter the following code:)


Onclipevent (load) {
this._x = 180;
this._y = 300;
_root.ss.createtextfield ("tt", 1, 70, 50, 100, 20);
_root.ss.tt.textcolor = 0xff0000;
_root.ss.createemptymovieclip ("Louding", 2);
With (_root.ss.louding) {
LineStyle (0, 0x0000ff, 0);
MoveTo (0, 0);
Starting point
Beginfill (0xff0000, 100);
LineTo (0, 10);
LineTo (10, 10);
LineTo (10, 0);
Endfill ();
}
_root.ss.createemptymovieclip ("Loudingk", 3);
With (_ROOT.SS.LOUDINGK) {
LineStyle (0, 0x000000, 100);
MoveTo (0, 0);
Starting point
LineTo (0, 10);
LineTo (200, 10);
LineTo (200, 0);
LineTo (0, 0);
}
}
Onclipevent (enterframe) {
Load = Int (_root.getbytesloaded ()/_root.getbytestotal () *100);
_root.ss.tt.text = "Loading" +load+ "%";
_root.ss.louding._width = 2*load;
if (_root.getbytesloaded () = = _root.getbytestotal ()) {
_root.play ();
}
}


Effect as shown:



Tips: A simple way to test the loading effect of the machine

After ctrl+enter often do not see the loading effect began to play the main animation, want to clearly preview to the effect of loading, a very simple way is: Ctrl+enter after the test animation playback state again Ctrl + Enter to see the loading effect clearly, in addition can change the speed of the simulation modem, in the Test Animation window, from the Debug menu can choose 14.4, 28.8, 56K and so on a few speed, or custom.

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.