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

Flash动画制作
巧用超级解霸在Flash V5.0中插入录像
教你用Flash MX来制作简单的课件界面
Flash MX 2004 ActionScript图文教程(二)
Flash MX 2004 ActionScript图文教程(三)
Flash MX 2004 ActionScript图文教程(四)
Flash MX 2004 ActionScript图文教程(五)
Flash MX 2004 ActionScript图文教程(六)
flash场景之间相互跳转的实现方法
Flash本地加密
FLASH -- 关于变量的问题FLASH -- 关于变量的问题
Flash5 画任意直线教程
Flash MX 视频导入功能详解
制作飞舞的蝴蝶
Flash MX 2004 ActionScript图文教程(七)
Flash MX 2004 ActionScript图文教程(八)
Flash MX 2004 ActionScript图文教程(九)
Flash MX 2004 ActionScript图文教程(十)
Flash教程 飞翔的文字
Flash MX 2004 ActionScript图文教程(十一)
制作Flash网站技巧拾零

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


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

可以测试你的影片了。