Photoshop Tutorials, Flash Tutorials, 3Ds Studio Max Tutorials, Web Design Tutorials |
Home | Submit Tutorial | Top Sites | Free Templates (NEW) | Website templates | Privacy Policy | Link Exchange | Contact Us |
|
Welcome To ProDesignHost.com Flash Tutorials Area - Let Is Snow in Flash MX
Introduction
In this tutorial I'm going to show you how to create a dynamic snow effect. This can really give the final touch to a christmas card. The snow is made with ActionScript so we don't need to tween each flake. The snow will fall in the direction of the mouse, to simulate wind. Each flake will also be scaled to its speed. The slower the flake, the smaller (because it's farther away). We'll also add a bit of randomization, so the flakes don't all fall in the same direction. Setting up the stage First set the framerate to 25 fps. If you want a different framerate, you'll have to edit the code. Otherwise everything will move too fast or too slow. Now create a little circle on the stage, roughly the size you want your snowflakes to be. Now turn it into a sybmol. Call the symbol "snowflake" and press the "Advanced" button in the bottom right corner. Check the "Export for ActionScript" checkbox, and enter "snowflake" as linkage. The Code With the graphics sorted out, you only have to copy and paste this code into the first frame. Don't forget to edit the width, height and total variables to the values you want.
If you want to know why the code works, read this, if you don't, your done. We start by defining a few variables that control what the code does. The first two, width and height, contain the width and height of the stage. If a snowflake is outside the stage, it gets wrapped to the other end. The last one, total, contains the number of snowflakes that need to be created. Then comes the loop that creates the snowflakes. Inside the loop, the first that we do, is take the "snowflake" symbol out of the library and put it on the stage with attachMovie. attachMovie takes 3 parameters, the linkage (symbol name), the instance name (name on the stage) and the depth. To get the depth, we use the function getNextHighestDepth. Then put the snowflake on a random point within the stage limits. Math.random returns a random number between 0 and 1. Next we define the yspeed and speed variables. The yspeed variable controls the speed that the snowflake travels at along the y-axis. The speed variable controls the speed that the snowflake travels at in any direction. The real x and y speeds are later calculated from these variables. After that, the x and yscale properties are changed according to the speed. The larger the speed and yspeed values are, the larger the snowflake. Then comes the onEnterFrame function. This function moves the snowflake. Inside the function, we first calculate the angle of the mouse, relative to the point (0, width/2). Math.atan2 returns the angle in radians. We then add 90 degrees (in radians) so the flakes will fall down instead of to the right (0 degrees is right in Flash). Then we move the movieclip along the y-axis. We take the sine of the angle, and multiply it by the speed. Math.abs is used so the function will always return a positive value so the snowflakes won't fall upwards. We also add yspeed, so the flakes won't all fall in the same direction. Then we move the movieclip along the x-axis by taking the cosine of the angle and multiplying it by the speed. Then we check if the snowflake isn't outside the stage. If it is, we wrap it to the other side. That's it? Jup, that's it. If you have any comments, please post them in this topic. If you have any questions, you can always open a topic in the "Flash" section of the forums. You can download the zip file attached to this tutorial for the FLA and SWF files. You can download source file of this tutorial. Author: MicrOchip
|
|
Premium Partners | |||||
|
|||||
Free website templates and paid web templates are great tools to make your websites look perfect! You will save time and money with our flash templates and free website templates
Our visitors are satisfied with the quality of our free and paid website templates! Please visit our free website templates and paid website templates sections. We offer free web templates, free web layouts, free web page templates and other stuff for free download. All templates come with the html and external css file so you may easily edit HTML with your favorite HTML editor. Feel free to download our free web templates for your personal websites. Terms of use depend upon the website template vendor. |
Home | Submit Tutorial | Top Sites | Free Templates | Website templates | Privacy Policy | Contact Us |