View comments | RSS feed

Suggestions for organizing your classes

Unlike previous ActionScript versions, ActionScript 3.0 does not have the one file, one class restriction that limits you to using only one class per file. Using ActionScript 3.0, you can save the source code for more than one class in a single .as file. In some cases, it might seem more convenient to pack multiple classes into a single source file, but in general, this is considered a bad programming practice, for a couple of reasons:

For these reasons, Adobe recommends that you always save the source code for each individual class in its own file, and give the file the same name as the class.


Flash CS3


Comments


Todays Past said on Jul 31, 2008 at 3:18 PM :
Continuing down the lost path.

You state that multiple classes per file is bad. But earlier pg28 you stated

"import flash.display.MovieClip;

Alternatively, you can import the package that contains the MovieClip class, which is equivalent to writing separate import statements for each class in the package:

import flash.display.*;"

I'm assuming that flash.display has more then just MovieClip in it.

Maybe you can use flash as an example of what good organization is, beyond the simple one file one class rule of thumb. Again assuming I'm understanding this at this time.

Show us a more complex package/file that is "good" and explain why its good.
Joe ... Ward said on Aug 7, 2008 at 11:03 AM :
When importing packages, you can think of the package names as directories and, if you follow the recommendation of one class per file, you can think of the classes as files within the directory. (In fact, this is how the ActionScript compiler finds the classes.)

Thus the import statement: import flash.display.*
does not import a single "file" containing all the classes in the flash.display package. Rather, it imports all the classes in this package. These classes are still defined one per file.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000034.html