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

Flash动画制作
Flash 3d效果精彩实例(5)
贺新年 制作五彩缤纷焰火动画
FlashMX2004中的XML应用之原理篇
制作一个骄艳的鲜花情人Flash贺卡
有趣 用Flash制作互动的小人
Flash制作鸡年新春动画贺卡
Flash MX 2004 UI组件系列教程(3)
Flash加载外部文件(5)
Flash MX 2004 UI组件系列教程(4)
Flash加载外部文件(2)
Flash加载外部文件(3)
一个最简便的代码实现任意数字和0的来回跳转
让Flash课件中测试题信手拈来
MX中如何实现swf文件的完美跳转
三分钟理解Flash中的级别关系
flash与ASP通信的几种方法
flashMX2004视频插件的应用教程
如何做好一个多人配合的flash项目
AS计算方面的错误
如何防止SWF文件被反编译

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


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

可以测试你的影片了。