flex 雪花效果

本人学flex 就这么几天[高手就不要看了]

1 package {
2 import Snow.Snow;
3
4 import flash.display.Sprite;
5
6 public class Test extends Sprite
7 {
8 public function Test()
9 {
10 var snow:Snow = new Snow();
11 stage.addChild(snow);
12 }
13 }
14 }
  

  雪花容器

1 package Snow
2 {
3 import flash.display.Sprite;
4 import flash.events.Event;
5
6 public class Snow extends Sprite
7 {
8 public function Snow()
9 {
10
11 for(var i:int = 0;i<1000;i++)
12 {
13 addSnow();
14 }
15 }
16
17 private function addSnow():void
18 {
19 var sprite: SnowMeta = new SnowMeta();
20
21 sprite.x = Math.random()* 1000;
22 sprite.y = Math.random()* 400;
23
24 addChild(sprite);
25 }
26 }
27 }

雪花 对象

1 package Snow
2 {
3 import flash.events.Event;
4 import flash.text.TextField;
5 import flash.text.TextFormat;
6
7 public class SnowMeta extends TextField
8 {
9 private var step:int = 1;
10
11 public function SnowMeta()
12 {
13 addEventListener(Event.ADDED_TO_STAGE,activection);
14 addEventListener(Event.REMOVED_FROM_STAGE , desactivection);
15 }
16
17 private function activection(e:Event):void
18 {
19 var tformat :TextFormat = new TextFormat();
20
21 tformat.color = 0xffffff;
22 defaultTextFormat = tformat;
23 text = ".";
24
25 scaleX*=Math.round(Math.random()*3);
26 scaleY*=Math.round(Math.random()*3);
27
28 step = scaleY;
29
30 addEventListener(Event.ENTER_FRAME,frame);
31 }
32
33 private function desactivection(e:Event):void
34 {
35 removeEventListener(Event.ADDED_TO_STAGE,activection);
36 removeEventListener(Event.REMOVED_FROM_STAGE,desactivection);
37 removeEventListener(Event.ENTER_FRAME,frame);
38 }
39
40 private function frame(e:Event):void
41 {
42 if(x> Math.random()* 1000)
43 {
44 x -= step;
45 }
46 else if(x <= 0)
47 {
48 x = 1000;
49 }
50 else if(Math.round(Math.random()*2)==2)
51 {
52 x += step;
53 }
54 else
55 {
56 x -= step;
57 }
58
59 //吹风效果
60   //x-=3;
61  
62 y+= 1;
63
64 if(y > 400)
65 y=0;
66 }
67 }
68 }
原文地址:https://www.cnblogs.com/czjone/p/1930851.html