当前位置: 首页 > 图文教程 > Flash动画 > Flash动画制作 > Flash AS3.0菜鸟学飞教程:含有多个类的AS3类文件

Flash动画制作
Flash巧妙绘制卡通澳大利亚夏日海滩
Flash CS3教程:绘制小奶瓶图标
Flash绘画实例:青春靓丽美女
制作Flash MTV前音乐和矢量素材的处理
Flash入门教程:鼠标跟随星星动画
鼠标滚轮事件滚动有Flash动画的网页
Flash绘画技巧之关于动画中的云
Flash中不能导入WAV声音的解决办法
Flash绘画实例:卡通铅笔图标
Flash广告点击率的深入研究
Flash绘制云彩的简单方法
Flash Web结构之背景层浅析
全Flash动画网站的实现详细教程
Flash Web结构之数据显示层
Flash Web设计团队协作
去除Flash动画在线播放限制的技巧
Flash逐帧和补间制作小野人摇滚动画
合并不同帧频(fps)的Flash文件
电子杂志设计制作常用Flash技术
Flash临摹著名画家徐悲鸿的骏马图

Flash动画制作 中的 Flash AS3.0菜鸟学飞教程:含有多个类的AS3类文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-22   浏览: 134 ::
收藏到网摘: 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. class MyClass {
5. function MyClass() {
6. var helper:MyHelper = new MyHelper();
7. }
8. }
9. }
10. class MyHelper {
11. function MyHelper() {
12. var helper:HelpersHelper = new HelpersHelper();
13. }
14. }
15. class HelpersHelper {
16. function HelpersHelper () {
17. }
18. }

注意:在包块中最多只能定义一个类。在同一个文件中的辅助类不是包块的一部分,并且只能在此文件中可见和被使用。

下面我们将我们将我们的类改写成上述的packge类形式。我们将下面的代码都写在一个DocumentClass.as的文件中,然后在fla文件中的属性面板中的Document Class输入框中输入DocumentClass类名。

1. 代码:
2.

3. package {
4. import flash.display.MovieClip;
5. import flash.display.Sprite;
6. import flash.events.MouseEvent;
7. // Document Class
8. public class DocumentClass extends MovieClip {
9. private var _circle:Drag_circle;
10. private const maxBalls:int=100;
11. public function DocumentClass() {
12. var i:int;
13. for (i=0; i <= maxBalls; i++) {
14. _circle=new Drag_circle ;
15. _circle.scaleY=_circle.scaleX=Math.random();
16. _circle.x=Math.round(Math.random() * stage.stageWidth -
17.

18. _circle.width);
19. _circle.y=Math.round(Math.random() * stage.stageHeight -
20.

21. _circle.height);
22. addChild(_circle);
23. }
24. }
25. }
26. }
27. import flash.display.Sprite;
28. import flash.events.MouseEvent;
29. class Drag_circle extends Sprite {
30. private var _circle:Sprite;
31. public function Drag_circle() {
32. _circle=new Sprite ;
33. _circle.graphics.beginFill(0xff0000);
34. _circle.graphics.drawCircle(-5,-5,10);
35. _circle.graphics.endFill();
36. addChild(_circle);
37. this.buttonMode=true;
38. _circle.addEventListener(MouseEvent.CLICK,onClick);
39. _circle.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
40. _circle.addEventListener(MouseEvent.MOUSE_UP,onUp);
41. }
42. private function onClick(event:MouseEvent):void {
43. trace("circle clicked");
44. }
45. private function onDown(event:MouseEvent):void {
46. _circle.startDrag();
47. }
48. private function onUp(event:MouseEvent):void {
49. _circle.stopDrag();
50. }
51. }

可以测试你的影片了。