Flash practical programming Four---the production of snow animation

Source: Internet
Author: User
Programming

  Ideas:

When the main scene is loaded, a certain number of snowflakes are randomly distributed on the screen, after each frame play, these snowflakes will be in the x axis and the y direction of the random displacement, so as a whole to produce snow effect.

 Steps:

1. Open Flash MX 2004, new document, document size 550*400 pixel, frame frequency set to 25FPS.

2. Draw a snowflake on the stage with a line tool, select the snowflake, press F8 to convert it to a movie clip, and delete the main scene snowflake movie clip.

3. Press Ctrl+l to open the library, select the Snowflake movie clip in the library, right-click, select "link" in the pop-up menu, and in the Next Pop-up Link Properties window, set the identifier to snow, and tick before "Export for action script" and "Export in first frame".

4. Back to the main scene, select Layer 1 frame 1th, press F9 to open the Action Script editing window, enter the following code:

This.onload = function () {
n = 60;
var i = 1;
while (n >= i) {
This.attachmovie ("Snow", "snow" + I, I);
var a = Math.Round (Math.random * () + 41);
var B = Math.Round (Math.random () + 51);
With (this["snow" + i]) {
_x = Math.random * ();
_y = * Math.random ();
_xscale = A;
_yscale = A;
_alpha = b;
_rotation =a;
this["Snow" + i].x = Math.Cos (Math.PI * math.random ());//The increment of displacement after each frame of the snowflake along the x axis
this["Snow" + I].y = 2*math.random (); The increment of the displacement after each frame of the snowflake along the y axis
}
i++;
}
}
This.onload ();
This.onenterframe = function () {
var a = 1;
while (n>= a) {
With (this["snow" + A]) {
_x = x;
_y = y;
_rotation = y;
if (_y > 400) {
_y = 0;
}else if (_x>550) {
_x=0;
}else if (_x<0) {
_x=550;
}
}
a++;
}
}

5. Press Ctrl+enter to test the film, the effect is as follows:

http://www.flash8.net/bbs/UploadFile/2005-6/2005619134418354.swf

Note: The while loop is used here, and of course it is available in the For loop.



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.