I’ve been a PrimalScript addict for a few months now, after being hooked by Chafic. I create all my classes in it, but still wound up doing a lot of setup work in the Flash IDE for creating instances, laying out stuff, etc. Occasionally I’d throw in an #include to an external .as file, but that never felt exactly right.
At the O’Reilly table at FlashForward, I picked up the little preview booklet of ActionScript 2.0 Essentials. I’d read the excerpts before on line, but had another look at them. Now I’ve converted a few of my projects to implement an application class. The class does all the set up and layout and instantiation. You start it with a public static main() function, where you can pass in some parameters. My projects now look something like this:
On the timeline:
sourceURL="project.xml"; MyApplication.main(_root, sourceURL);
and the class:
class MyApplication {
// var declarations
private var __parentClip:MovieClip;
private var __sourceURL:String;
public function MyApplication(clip:MovieClip, url:String){
__parentClip = clip;
__sourceURL = url;
init();
}
private function init(){
// load xml, attach or create clips/components to __parentClip, etc.
// call other private functions as needed
}
public static function main(clip:MovieClip, url:String){
var app = new MyApplication(clip, url);
}
// other functions as needed
}
I know it’s not the ONLY way to do things, but I’m liking it!