Posted Wednesday, February 21, 2007 2:55:13 PM by David Stiller
Depending on my mood, I may precede certain variable names with a small prefix that describes the type of object they point to. For example, I may give a movie clip the instance name
mcBall, rather than just
ball. Why? Well, it allows me to see at a glance that I’m dealing with a
MovieClip instance, which can come in handy during coding and also while I’m poking through the Debugger panel. It doesn’t have any measurable effect on the functionality of the variable … it’s just one of those things you get used to. I certainly don’t always adhere to this convention, but when I do, I’m practicing something called Hungarian notation, which has a decent pedigree (at least, in computer years).
Flash provides at least one naming convention that actually can make a practical difference, if you follow the suggested suffixes in the “About using suffixes to trigger code hints” section of Learning ActionScript 2.0 in Flash. I’m not especially a fan stylistically, but, for example, if I name that ball clip
ball_mc, I’ll get automatic code hinting for the
MovieClip class (and so will you) in ActionScript 1.0 and 2.0. A full list of suffixes is listed in that section. Code hinting is definitely a useful tool, because I’m not always familiar with the class members of the object at hand.
What if you don’t like suffixes? Or prefixes, for that matter? Well, if you use AS2’s strong typing syntax (the
:Number in something like
var total:Number = 5;), it doesn’t matter what you name your variable: you’ll get code hinting if you want it (see File > Preferences > ActionScript). That’s fine for everything but movie clip instance names, which aren’t necessarily declared as variables. But … see, if you declare instance names anyway — even though you don’t need to — you get the benefit of code hinting regardless of the instance name.
With a simple line like this …
… even though you haven’t set that instance to anything, you’ll get
MovieClip-centric code hints for subsequent references to that instance name in your code.
Category tags: Flash