Actionscript Basics: Identifiers

What are Identifiers?

When you are writing your code many of the elements are predefined. That is the words you are using have already been defined. Other elements you must create are defined by you. That is you get to make up the name assigned to these elements. Movieclip Instance names, Function names, Class names and Variable names are defined by you. That is you make up the names for yourself. All of these names are Identifiers.

When naming an Identifier you must follow a few simple rules.

  • The name must begin with a non numeric character
  • The name can not contain spaces or special characters. The _ (underscore) and $ (dollar sign) are exceptions to this rule

Foe example the following names work as identifiers:

  • _index
  • gallery
  • gallery_mc
  • ButtonAnimator

The following would not work as identifiers for various reasons:

  • 5_button – begins with a number
  • button 5 – contains a space
  • button*5 – contains a special character (*)

Descriptive names

Using names that describe the use of the element being named is a good idea. This creates code that reads well comments itself.

Good naming should be balanced by creating names that are not too long and don’t encourage spelling errors.

Name Extensions

Adobe suggests the use of extensions at the end of Identifier names. These extensions help label your Identifiers as being of a particular type. They also work with the code editor in Flash to give targeted code hints. All of the extensions begin with the _ followed by a few letters. Here’s a list of extensions, each is followed by the type it represents:

  • _mc – MovieClip
  • _sprite – Sprite
  • _txt – TextField
  • _str – String
  • _array – Array

Example Identifiers

Here are a few names that might used for identifiers:

  • home_mc – instance of a movie clip on the stage, maybe the button labeled Home
  • icons_sprite – instance name of a sprite containing icons
  • button_array – an array containing a list of buttons

Leave a Reply

Your email address will not be published. Required fields are marked *