Create a snowflake in Flash
Thursday, December 6, 2007Some readers have asked me how it was created snowflake, so realistic, the Widget Christmas. Those who have downloaded the source probably already knows ... however, was very simple. First of all I selected the Brush tool in Flash and I have designed a point.
![]() | ![]() |
I've turned this into a symbol and I have two effects applied in the right sequence: bevel and blur:
![]() | ![]() |
The result was: 
In this MovieClip (symbol) I have associated a simple class CNeve which creates de facto intelligence staple of himself:
- { CNEVA class extends MovieClip (
- _interval; var private _interval;
- _maxy: Number ; var private _maxy: Number;
- / /
- CNEVA function () (
- this , "_move" , 25 ) ; _interval = setInterval (this, "_Move", 25);
- ( ( Stage . height + 256 ) / 2 ) +_getRndRange ( - 20 , - 7 ) ; _maxy = Math. round ((Stage. height + 256) / 2) + _getRndRange (- 20 - 7);
- )
- / /
- _getRndRange ( min : Number , max : Number ) : Number { private function _getRndRange (min: Number, max: Number): Number (
- = Math . floor ( Math . random ( ) * ( max- min + 1 ) ) + min ; var randomNum: Number = Math. floor (Math. random () * (max-min + 1)) + min;
- randomNum return;
- )
- / /
- _move ( ) { _Move private function () (
- 1 , 5 ) ; _y + _getRndRange = (1, 5);
- _getRndRange ( - 50 , 50 ) ) > 0 ) ? 1 : - 1 ; _X + = ((_getRndRange (- 50, 50))> 0)? 1 - 1;
- 1 , 5 ) ; _rotation + _getRndRange = (1, 5);
- _y>_maxy ) { if (_y> _maxy) (
- _interval ) ; clearInterval (_interval);
- )
- ; updateAfterEvent ();
- )
- )
The method _move() contains the intelligence of the staple, or the fall, very simple. By changing the random _x += ((_getRndRange(-50, 50))>0) ? 1 : -1;, _x += ((_getRndRange(-50, 50))>0) ? 1 : -1;, example by including a _getRndRange(-550, 50), you can add a wind effect, namely the flakes fall with a particular slope. In particular, the flakes can send to either side using a code like this:
- _getRndRange ( _getRndRange ( - 350 , - 50 ) , _getRndRange ( 50 , 350 ) ) ) > 0 ) ? 1 : - 1 ; _X + = ((_getRndRange (_getRndRange (- 350, - 50), _getRndRange (50, 350)))> 0)? 1 - 1;
The rotation _rotation += _getRndRange(1, 5); then, gives further details to staple himself.
When I create a staple (see function creaFiocco() below) I also added an alpha=90 a scale random, to have snowflakes of various sizes.
- / / Create staple
- creaFiocco function () (
- 20 , 100 ) ; var s = randRange (20, 100);
- - Math . floor ( ( Stage . width - 320 ) / 2 ) , Math . round ( ( Stage . width + 320 ) / 2 ) ) ; var x = randRange (- Math. floor ((Stage. width - 320) / 2), Math. round ((Stage. width + 320) / 2));
- . floor ( ( ( Stage . height - 256 ) / 2 ) ) - 10 ; var y = - Math. floor (((Stage. height - 256) / 2)) - 10;
- "neve" , "neve_" + index , index , { _x :x, _y :y, _xscale :s, _yscale :s, _alpha : 90 } ) ; c_mc. attachMovie ( "snow", "neve_" + index, index, (_X: x, _y: y, _xscale: s, _yscale: s, _alpha: 90));
- index + +;
- index> 1000 ) { if (index> 1000) (
- ; index = 1;
- "c_mc" , 2 ) ; c_mc = createEmptyMovieClip ( "c_mc", 2);
- )
- )
And that's all ...
Forgot ... Greetings to all and Happy holidays ... ![]()






















Dieg0 said:
Check my site: http://www.Dieg0.com.ar
Regards,
Diego
Giovambattista Fazioli said:
@ Diego0: Thanks for links
On the site of Diego Javascript is a script that simulates also falling flakes of snow. The advantage of using Javascript is to place the flakes on our page, which with Flash - while possibiloe is through transparency - prevents then made the selection.
Chris said:
It hello son came to browse in vedendoti MyBlogLog on my blogghetto. It is ignorant about flash and the surrounding area, I did not know was OOP action script. Who knows when it will give us a look, what attracts me
Hello hello
Giovambattista Fazioli said:
@ Chris: Thanks for visiting! I saw that you're comentar in OO programming with C + +! Excellent choice. To deal well OO concepts must surely know that the C C + +. Actionscript is not as "pure" like C + +, although each version is closer and closer to the actual "close" OO development methodologies. However if you can work with Flash, including Actionscript 2.0, you can surely find many things enlightening.
Widget Christmas: snow falling in Flash | Undolog.com said:
[...] Update: service unavailable - See Create a snowflake in Flash [...]