Instance Naming

Instance Naming

Flash CS4 ActionScript 3.0 Tutorial


How to Assign a Button Symbol, Movie Symbol, Input Text Object, or Dynamic Text Object a Variable Name to be Used by ActionScript



Whenever you create an instance name, you are adding a new variable to your ActionScript. Instance names can be added to Button Symbols, Movie Symbols, Input Text objects, and Dynamic Text objects. To enable code hinting in the ActionScript panel, be sure to add Button (_btn), Movie (_mc) and Text (_txt) suffixes to your instance names. In other words, you might name your Movie Symbol, spaceMonster_mc.

Naming an Instance

When naming variables or instances, observe the following rules:

No spaces

Use numbers and letters

Avoid using any special characters

Character exceptions are ($, _)

Don't use any reserved words (they appear in blue)

Never start an instance with a number

Assign a name that makes sense

Tutorial Elements

Movie Symbol with instance name myMovie_mc


Step One

Add a Movie Symbol to the stage and select the symbol with the Selection tool (v key).

Step Two

Open the Properties panel (Cmd/F3 (PC-Ctrl/F3)) and type in the name myMovie_mc for the Instance Name.

Step Three

Add a new layer called Actions.

Step Four

Option double-click (PC - Alt double-click) the keyframe in the Actions layer to open the ActionScript panel.

Step Five

Copy/Paste the following code to the ActionScript panel.

myMovie_mc.scaleX = 2;

Step Six

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). By setting scaleX equal to 2, the object becomes twice as wide as its original size.

Camel Case

A common practice when naming variables and instances is to use camel case. Camel case variables start with small letters. Each new word starts with a cap. There are no spaces.

Blue Box converted to camel case becomes blueBox.


Stock Images