This short article is on variable naming in the new Actionscript 2.0 (and 1.0, I guess).
I like to bring some light to a little known fact about naming variables in 1.0:
You know how some variables will bring up a list of available functions and properties when you type a dot at the end of it?
//syntactically wrong, but for the sake of example my_mc. // will bring up a list of functions available to that variable // whereas... myMC. // won't display anything
What triggered the list of available functions for the first command was actually the suffix “_mc”. The variable types in AS x.0 (for both versions 1 and 2) each has its own suffix to enable what is called Automatic Code Hinting. If you’re anything like me, I don’t like typing out some of Flash’s really long function names like
_mc.createEmptyMovieClip(...); //also case-sensitive, no less
so this is where suffix-ing your variables comes in handy.
Like I mentioned, each data type (Array, Color, MovieClip, etc) has its own little tag along suffix that will enable the code hinting. They are as follows: (available for both AS 1.0 and 2.0, incomplete)[list]Array: _array
[*]XMLSocket: _xmlsocket[/list]As you can see, the suffix for any given type is pretty obvious.
So how do we apply this? Well, given that list, you can now add those suffixes to your variable names (like my_array, preload_sound, etc) and a menu with every available function for that type will appear. So now you can see why, in the code above, my_mc triggers a menu and myMC does not. Use these suffixes to your advantage, whether for speed or reliability, it is your friend.
Now on to AS 2.0…
2.0 also offers those suffixes that were listed above as well as some new ones: (AS 2.0 only):[list]Camera: _cam
ContextMenu: _cm (my next tutorial will be on this)
Now there is another way to display code hints without the use of suffixes. It is implemented in AS2.0’s new style of variable declaration:
//Now instead of using _str to display the menu like: my_str. //You can have the same menu appear but name the variable whatever you like: var myString:String; myString. // pops-up menu with string functions
Now if you haven’t seen this syntax for variable declaration, don’t
fear. It’s quite simple, really:
[font=courier new]var variable_name:Data Type[/font]
It’s up to you whether you want to use var or not, it doesn’t make a difference. But if you do, a menu of available data types appears when you type that colon used in the syntax (how nice of them :love:**).
Well that’s all I have for now. If you have any questions/corrections to this article, let me know.