Even though it is late Friday/early Saturday, I’ve got to write this one down:
Through an internal implementation of ActionScript 2.0’s compiler (which compiles code into ActionScript 1.0), Peter Hall discovered this little trick.
Here’s a shortened (and more obscured) example:
Actor.as:
class Actor extends MovieClip {
static var id = (id="__Packages.Actor")+
(Object.registerClass(id,Actor)?"":"");
public function Actor() {
trace("Action!");
}
}
To test:
import Actor;
attachMovie(Actor.id, "_mc", 1);
This keeps the number of static variables to a minimum (one). Of course, this trick works only if the compiler uses the “__Packages.” prefix to the class path internally, and may not work in future versions of Flash. Nevertheless, it’s a very cool trick.