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

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菜鸟学飞教程:含有多个类的AS3类文件


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

可以测试你的影片了。