Tutorials Books Videos Forums

Change the theme! Search!
Rambo ftw!

Customize Theme


Color

Background


Done
Look, an author!

AS 2.0 Variable Hints [Coding Efficiency]

by Thoriphes   | filed under Flash and ActionScript

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?

For example:

// 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

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)

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):

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:

var variable_name:DataType;

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!).

Well that's all I have for now. If you have any questions/corrections to this article, let me know.

Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence, ads, and algorithm-driven doodads. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums.

Your support keeps this site going! 😇

- Thoriphes

The KIRUPA Newsletter

Thought provoking content that lives at the intersection of design 🎨, development 🤖, and business 💰 - delivered weekly to over a bazillion subscribers!

SUBSCRIBE NOW

Creating engaging and entertaining content for designers and developers since 1998.

Follow:

Popular

Loose Ends

:: Copyright KIRUPA 2026 //--