A-A+

flash雪花飘as代码

2015年09月17日 前端设计 暂无评论 阅读 10 views 次

发现一段不错的 flash 雪花飘纯 as 代码,可以在制作电子杂杂或者是透明 flash 的时候来使用,效果挺棒的,下面主要是纯 as 实现的雪花飘,新手也可以拿来练习使用,as 实例代码如下:

  1. insert into filecontent(title,content,filesendtime,filesendid,siteindex,s  
  2. ystype,isown,z_type) value('雪花飘啊飘','  
  3. ///////////////////////////////////////////////////////////////////////////  
  4. // 照着turbine前辈的早先的一个文件做的,他的用到了类,  
  5. // 本想也用类来写,无奈as2的类暂时用不熟,mx的类又不想再用,  
  6. // 所以只好凑合凑合,拼个效果出来先,里面好多代码看上去乱糟糟的  
  7. // 呵呵,先就这样了,看来得抓紧学习类的使用,呼呼呼呼  
  8. // 没做任何注释,对不起大家了,谁帮忙注释下,注释的好的加分哦嘎嘎...  
  9. // 源代码就不帖了,反正把这些代码全复制就可以了  
  10. // 运行环境flashMX2004  
  11. ///////////////////////////////////////////////////////////////////////   
  12.   
  13. var sceneWidth = sceneHeight=300;  
  14. var sideDisWidth = Stage.width/2-sceneWidth/2;  
  15. var sideDisHeight = Stage.height/2-sceneHeight/2;  
  16. var snowNum = 80;  
  17. var snowSpace:MovieClip = _root.createEmptyMovieClip("room", 1);  
  18. function addMasker() {  
  19. _root.createEmptyMovieClip("masker", 10000);  
  20. with (masker) {  
  21. beginFill(0x000550, 100);  
  22. moveTo(sideDisWidth, sideDisHeight);  
  23. lineTo(sideDisWidth+sceneWidth, sideDisHeight);  
  24. lineTo(sideDisWidth+sceneWidth, sideDisHeight+sceneHeight);  
  25. lineTo(sideDisWidth, sideDisHeight+sceneHeight);  
  26. lineTo(sideDisWidth, sideDisHeight);  
  27. endFill();  
  28. }  
  29. snowSpace.setMask(masker);  
  30. createSnow();  
  31. }  
  32. function snowProperty(snow, w, h) {  
  33. snow._x = sideDisWidth+Math.random()*w;  
  34. snow._y = sideDisHeight+Math.random()*h;  
  35. snow._rotation = Math.random()*120+30;  
  36. snow.stepX = Math.cos((snow._rotation*Math.PI)/180);  
  37. snow.stepY = Math.random()*2+1;  
  38. setInterval(snowFall, 30, snow);  
  39. }  
  40. function drawSnow(snow:MovieClip, radius:Number) {  
  41. var p = radius*.9;  
  42. with (snow) {  
  43. colors = [0xCCCCCC, 0xFFFFFF];  
  44. alphas = [100, 100];  
  45. ratios = [0, 255];  
  46. matrix = {matrixType:"box", x:-Math.random()*2*radius, y:-Math.rand  
  47. om()*2*radius, w:2*radius, h:2*radius, r90/180)*Math.PI};  
  48. beginGradientFill("radial", colors, alphas, ratios, matrix);  
  49. moveTo(0, -radius);  
  50. curveTo(p, -p, radius, 0);  
  51. curveTo(p, p, 0, radius);  
  52. curveTo(-p, p, -radius, 0);  
  53. curveTo(-p, -p, 0, -radius);  
  54. endFill();  
  55. }  
  56. snowProperty(snow, sceneWidth, sceneHeight);  
  57. }  
  58. function createSnow() {  
  59. var n = 0;  
  60. while (n<snowNum) {  
  61. var snow:MovieClip = snowSpace.createEmptyMovieClip("s"+n, n);  
  62. var radius:Number = Math.random()*3;  
  63. drawSnow(snow, radius);  
  64. n++;  
  65. }  
  66. }  
  67. function snowFall(snow) {  
  68. snow._x += snow.stepX;  
  69. snow._y += snow.stepY;  
  70. if (snow._x<sideDisWidth) {  
  71. snow._x = sideDisWidth+sceneWidth;  
  72. }  
  73. if (snow._x>sideDisWidth+sceneWidth) {  
  74. snow._x = sideDisWidth;  
  75. }  
  76. if (snow._y>sideDisHeight+sceneHeight) {  
  77. snow._y = sideDisHeight;  
  78. }  
  79. }  
  80. addMasker();  
  81. _root.createEmptyMovieClip("myMC", 10);  
  82. with (myMC) {  
  83. lineStyle(1, 0xcccccc, 100);  
  84. moveTo(sideDisWidth, sideDisHeight);  
  85. lineTo(sideDisWidth+sceneWidth, sideDisHeight);  
  86. lineTo(sideDisWidth+sceneWidth, sideDisHeight+sceneHeight);  
  87. lineTo(sideDisWidth, sideDisHeight+sceneHeight);  
  88. lineTo(sideDisWidth, sideDisHeight);  
  89. var infor:TextField = myMC.createTextField("infor", 1, sideDisWid  
  90. th+sceneWidth-100, sideDisHeight+sceneHeight, 100, 20);  
  91. infor.autoSize="right";  
  92. infor.selectable=false;  
  93. infor.textColor = 0xcccccc;  
  94. infor.text = "by holybozo";  
  95. }  
  96. _root.createEmptyMovieClip("bg", -1);  
  97. with (bg) {  
  98. beginFill(0x999999, 100);  
  99. moveTo(0, 0);  
  100. lineTo(Stage.width, 0);  
  101. lineTo(Stage.width, Stage.height);  
  102. lineTo(0, Stage.height);  
  103. lineTo(0, 0);  
  104. endFill();  
  105. }  
标签:

给我留言