当前位置: 首页 > 图文教程 > Flash动画 > Flash动画制作 > Flash AS3.0菜鸟学飞教程:类的编写之不使用库元件

Flash动画制作
我是大导演 MTV创作速成教程
二合一按钮的制作
[DIY]这种相册你有吗?
教你一招绝的!把Flash动画转换成VCD视频
使用Flash MX的3个小技巧
Flash课件一网打尽
Flash Player 7 安全策略解析
FlashMX特效之扩散与挤压
Flash MX 2004 体验之旅
Flash使用技巧--用Flash制作拖拉式菜单
Flash使用技巧--用Flash制作转动的地球仪
Flash使用技巧--用Flash 5制作Winamp光谱柱的效果
Flash使用技巧--用Flash制作落地有声的瓶子
Flash使用技巧--用Flash 5巧做“弹出”效果菜单
Flash使用技巧--用Flash制作即指即现的广告条
用大师级软件MixFX轻松打造专业FLASH
用Flash MX快速制作沟通留言程序
用Flash制作动感效果的网页链接提示框
巧妙运用Flash MX 2004制作“拖曳配对题”
用Flash MX制作精彩的粉荷清波动画特效一例

Flash动画制作 中的 Flash AS3.0菜鸟学飞教程:类的编写之不使用库元件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-22   浏览: 53 ::
收藏到网摘: n/a

更多AS 3.0教程:http://www.ruanchen.com/"BORDER-RIGHT: #4b8be3 1px solid; BORDER-TOP: #4b8be3 1px solid; BORDER-LEFT: #4b8be3 1px solid; BORDER-BOTTOM: #4b8be3 1px solid" width="600" align="center" bgcolor="#dfeeff"> 1. 代码:
2.

3. package {
4.
5. import flash.display.MovieClip;
6. public class DocumentClass extends MovieClip {
7. // 属性
8. private var _circle:Drag_circle;
9. private const maxBalls:int = 100;
10. // 构造函数
11. public function DocumentClass() {
12.
13. var i:int;
14. // 循环创建小球
15. for(i = 0; i<= maxBalls; i++) {
16. // 创建可拖动小球的实例
17. _circle = new Drag_circle();
18. // 设置小球实例的一些属性
19. _circle.scaleY = _circle.scaleX = Math.random();
20. // 场景中的x,y位置
21. _circle.x = Math.round(Math.random() *(stage.stageWidth - _circle.width));
22. _circle.y = Math.round(Math.random() *(stage.stageHeight - _circle.height));
23. // 在场景上显示
24. addChild(_circle);
25. }
26. }
27. }
28. }

Drag_circle类 (绘制一个红色的圆,有拖拽功能)

1. 代码:
2.

3. package {
4.
5. import flash.display.Sprite;
6. import flash.display.Shape;
7. import flash.events.MouseEvent;
8.

9. public class Drag_circle extends Sprite {
10.
11. private var _circle:Sprite;
12.
13. public function Drag_circle() {
14.
15. _circle = new Sprite();
16. _circle.graphics.beginFill(0xff0000);
17. _circle.graphics.drawCircle(0, 0, 10);
18. _circle.graphics.endFill();
19. _circle.buttonMode = true;
20. addChild(_circle);
21.
22.
23. _circle.addEventListener(MouseEvent.CLICK,onClick);
24. _circle.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
25. _circle.addEventListener(MouseEvent.MOUSE_UP,onUp);
26.
27. }
28.
29.
30. private function onClick(event:MouseEvent):void {
31. trace("circle clicked");
32. }
33.

34. private function onDown(event:MouseEvent):void {
35. _circle.startDrag();
36. }
37.

38. private function onUp(event:MouseEvent):void {
39. _circle.stopDrag();
40. }
41. }
42. }

新建一个fla文件,保存在Document.as和Drag_class.as类同一目录中。注意:与上回讲的元件类不同在于,不再需要让场景中有任何内容,因为我们已在主类DocumentClass.as中动态的添加和显示了circle_mc。在属性面板中的文档类输入框中输入类名 DocumentClass,就可以测试了。(你可以尝试着给小球加入随机颜色或渐变颜色)