原帖地址:
http://www.wedoswf.com/questions/1622
这个是我们以前活动的喊话banner,是从 wonderfl上的效果改的。
效果见这里:http://swfsh.com/images/SwfSHBanner_0530.swf
下面是源代码:
代码
1. package
2. {
3. import flash.display.*;
4. import flash.events.Event;
5. import flash.geom.*;
6. import flash.text.*;
7.
8. /**
9. * 電光掲示板のテスト
10. */
11. [SWF(width="550", height="316", backgroundColor="0x000000", frameRate="24")]
12. public class Main extends Sprite
13. {
14. private var panel:Sprite;
15. private var data:BitmapData;
16. private var frameCount:int;
17. private var textField:TextField;
18. private var sourceSprite:Sprite;
19.
20. public function Main():void
21. {
22. if (stage) init();
23. else addEventListener(Event.ADDED_TO_STAGE, init);
24.
25. panel = new Sprite();
26. panel.rotationY = 25;
27. panel.rotationX = 25;
28. panel.y = 50;
29. addChild(panel);
30. }
31.
32. private function init(e:Event = null):void
33. {
34. removeEventListener(Event.ADDED_TO_STAGE, init);
35. sourceSprite = new Sprite();
36.
37. textField = new TextField();
38. textField.autoSize = TextFieldAutoSize.LEFT;
39. textField.height = 20;
40. textField.background = true;
41. textField.backgroundColor = 0xC0C0C0;
42. textField.selectable = false;
43. textField.x = -1;
44. textField.y = -2;
45. textField.text = "5月30日FLASH专家交流会火热报名中!!! 请访问 WWW.SWFSH.COM";
46.
47. var format:TextFormat = new TextFormat();
48. format.color = 0;
49. format.size = 14;
50. format.font = "宋体";
51. textField.setTextFormat(format);
52.
53. sourceSprite.addChild(textField);
54. data = new BitmapData(textField.width, 16);
55. data.draw(sourceSprite);
56. sourceSprite.removeChild(textField);
57. addChild(sourceSprite);
58. frameCount = -31;
59. addEventListener(Event.ENTER_FRAME, onEnterFrame);
60. }
61.
62. /**
63. * 逐帧绘制
64. */
65. private function onEnterFrame(event:Event):void
66. {
67. frameCount++;
68. if (frameCount > data.width)
69. frameCount = -31;
70. panel.graphics.clear();
71.
72. for (var y:int = 0; y < 16; y++)
73. {
74. for (var x:int = 0; x < 71; x++)
75. {
76. var pixel:uint;
77. if (x + frameCount < 0 || x + frameCount > data.width - 1)
78. pixel = 1;
79. else
80. pixel = data.getPixel(x + frameCount, y);
81.
82. if (pixel == 0)
83. drawDot(10 + x * 10, 40 + y * 10, 4.5, 0xFF0000, 0x800000);
84. else
85. drawDot(10 + x * 10, 40 + y * 10, 4.5, 0x600000, 0x400000);
86. }
87. }
88. }
89.
90. /**
91. * 具体的描点方法
92. * @param x 点の中心の X 座標
93. * @param y 点の中心の Y 座標
94. * @param size 点の大きさ
95. * @param colorLight 明るい場所の色
96. * @param colorDark 暗い場所の色
97. */
98. private function drawDot(x:Number, y:Number, size:Number, colorLight:uint, colorDark:uint):void
99. {
100. var colors:Array = [colorLight, colorDark];
101. var alphas:Array = [1.0, 1.0];
102. var ratios:Array = [0, 255];
103. var matrix:Matrix = new Matrix();
104. matrix.createGradientBox(size * 2,
105. size * 2,
106. 0,
107. x - size,
108. y - size);
109.
110. panel.graphics.lineStyle();
111. panel.graphics.beginGradientFill(GradientType.RADIAL,
112. colors,
113. alphas,
114. ratios,
115. matrix);
116. panel.graphics.drawCircle(x, y, size);
117. panel.graphics.endFill();
118. }
119.
120. }
121.
122. }
2. {
3. import flash.display.*;
4. import flash.events.Event;
5. import flash.geom.*;
6. import flash.text.*;
7.
8. /**
9. * 電光掲示板のテスト
10. */
11. [SWF(width="550", height="316", backgroundColor="0x000000", frameRate="24")]
12. public class Main extends Sprite
13. {
14. private var panel:Sprite;
15. private var data:BitmapData;
16. private var frameCount:int;
17. private var textField:TextField;
18. private var sourceSprite:Sprite;
19.
20. public function Main():void
21. {
22. if (stage) init();
23. else addEventListener(Event.ADDED_TO_STAGE, init);
24.
25. panel = new Sprite();
26. panel.rotationY = 25;
27. panel.rotationX = 25;
28. panel.y = 50;
29. addChild(panel);
30. }
31.
32. private function init(e:Event = null):void
33. {
34. removeEventListener(Event.ADDED_TO_STAGE, init);
35. sourceSprite = new Sprite();
36.
37. textField = new TextField();
38. textField.autoSize = TextFieldAutoSize.LEFT;
39. textField.height = 20;
40. textField.background = true;
41. textField.backgroundColor = 0xC0C0C0;
42. textField.selectable = false;
43. textField.x = -1;
44. textField.y = -2;
45. textField.text = "5月30日FLASH专家交流会火热报名中!!! 请访问 WWW.SWFSH.COM";
46.
47. var format:TextFormat = new TextFormat();
48. format.color = 0;
49. format.size = 14;
50. format.font = "宋体";
51. textField.setTextFormat(format);
52.
53. sourceSprite.addChild(textField);
54. data = new BitmapData(textField.width, 16);
55. data.draw(sourceSprite);
56. sourceSprite.removeChild(textField);
57. addChild(sourceSprite);
58. frameCount = -31;
59. addEventListener(Event.ENTER_FRAME, onEnterFrame);
60. }
61.
62. /**
63. * 逐帧绘制
64. */
65. private function onEnterFrame(event:Event):void
66. {
67. frameCount++;
68. if (frameCount > data.width)
69. frameCount = -31;
70. panel.graphics.clear();
71.
72. for (var y:int = 0; y < 16; y++)
73. {
74. for (var x:int = 0; x < 71; x++)
75. {
76. var pixel:uint;
77. if (x + frameCount < 0 || x + frameCount > data.width - 1)
78. pixel = 1;
79. else
80. pixel = data.getPixel(x + frameCount, y);
81.
82. if (pixel == 0)
83. drawDot(10 + x * 10, 40 + y * 10, 4.5, 0xFF0000, 0x800000);
84. else
85. drawDot(10 + x * 10, 40 + y * 10, 4.5, 0x600000, 0x400000);
86. }
87. }
88. }
89.
90. /**
91. * 具体的描点方法
92. * @param x 点の中心の X 座標
93. * @param y 点の中心の Y 座標
94. * @param size 点の大きさ
95. * @param colorLight 明るい場所の色
96. * @param colorDark 暗い場所の色
97. */
98. private function drawDot(x:Number, y:Number, size:Number, colorLight:uint, colorDark:uint):void
99. {
100. var colors:Array = [colorLight, colorDark];
101. var alphas:Array = [1.0, 1.0];
102. var ratios:Array = [0, 255];
103. var matrix:Matrix = new Matrix();
104. matrix.createGradientBox(size * 2,
105. size * 2,
106. 0,
107. x - size,
108. y - size);
109.
110. panel.graphics.lineStyle();
111. panel.graphics.beginGradientFill(GradientType.RADIAL,
112. colors,
113. alphas,
114. ratios,
115. matrix);
116. panel.graphics.drawCircle(x, y, size);
117. panel.graphics.endFill();
118. }
119.
120. }
121.
122. }
效果