开发者

How do I apply different classes to different frames in flash CS5?

I am coding in actionscript 3 and need some help with classes. I want the first frame to have its own class/开发者_如何学Pythonpackage and I want the other frames to share another class/package. How do I do this?


Don't. It is neither a clean nor a recommendable way to organize ActionScript code in your project. Use classes and packages the way they were intended: for object-oriented programming. In fact, you should use frame actions only if you have minor tasks to do, especially controlling the timeline (stop(); and such), or to create or remove objects at a point in time.

If you want your frames to spawn new behavior, create and/or remove class instances on the stage instead - they can be transparent or fill the entire stage, so they will not be noticed by users, but your program will have proper encapsulation. You can attach a Class to each MovieClip in your library, so you can put one in each frame of your timeline, and you can even edit the timeline of that MovieClip, if you want to.

Whichever you decide, you should read up on object-oriented programming in ActionScript here.


The timeline is, at the end of the day, a sub-class of a MovieClip. Each frame is a frame of that MovieClip, so you cannot associated a class with each frame. You could use a single class and use the "undocumented" addFrameScript to associate a method with each frame. Better yet, I'd probably just add a new MovieClip to each frame with its own unique subclass. So frame1's BaseClass would be Frame1MovieClip.as and frame2's BaseClass would be Frame2MovieClip.as. If you want the frames to share a class, just extend that frame across the number of frames you want.

           1  2  3  4  5
 layer2   [o]
 layer1      [o         ]

So "layer2" would contain a MovieClip with Frame1MovieClip.as as the BaseClass and layer 1 would have a different BaseClass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜