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

Flash动画制作
使用SetMask脚本制作沿路径运动的遮罩实例
Flash MX 2004 ActionScript图文教程(一)
拖出你的精彩:Flash MX课件中的拖动
Flash实例教程:鱼戏莲叶间
Flash MX pro的历史面板(一)
Flash MX pro的历史面板(二)
Flash MX pro的历史面板(三)
Flash常见问题解答集锦(1)
Flash MX行为功能初体验:相册的制作
Flash MX04文字特效:残影动画(图)
Flash游戏制作常用代码解析(图)
在Flash中巧妙替换字体
用FlashMX制作拖动悬浮窗口
让Flash课件在VCD上播放
PowerPoint中插入Flash动画的方法
使用Flash mx制作旋转的时钟效果
用Flash制作动感火焰字
Flash Mx使用技巧十二则
用Flash MX制作新年贺卡
Flash那样动感十足制作PPT按钮跟我来

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-22   浏览: 148 ::
收藏到网摘: 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. }

可以测试你的影片了。