138 Syntax and Language Fundamentals
10. Type the following code into the Actions panel:
var myExample:ConstExample = new ConstExample();
trace(myExample.EXAMPLE_PUBLIC); // output: Public access
This code instantiates the myExample instance and accesses the EXAMPLE_PUBLIC
property.
11. Select Control > Test Movie to test your document.
You see
Public access in the Output panel.
12. In the Actions panel, delete the trace statement that you added in step 10.
13. Type the following code into the Actions panel.
trace(myExample.EXAMPLE_PRIVATE); // error
The EXAMPLE_PRIVATE property is a private property, so it is available only within the
class definition.
14. Select Control > Test Movie to test your document.
You see
The member is private and cannot be accessed in the Output panel.
For more information on built-in classes and creating custom classes, see Chapter 7,
“Classes,” on page 225.
About keywords
Keywords are words in ActionScript that do one specific thing. For example, you use the var
keyword to declare a variable. The
var keyword is shown in the following line of code:
var myAge:Number = 26;
A keyword is a reserved word that has a specific meaning: for example, you use the class
keyword to define new a new ActionScript class; and you use the
var keyword to declare local
variables. Other examples of reserved keywords are:
if, else, this, function, and return.
Keywords cannot be used as identifiers (such as variable, function, or label names), and you
should not use them elsewhere in your FLA files for other things (such as instance names).
You have already used the
var keyword a lot, particularly if you read Chapter 4, “Data and
Data Types,” on page 71. ActionScript reserves words in the language for specific use.
Therefore, you can’t use keywords as identifiers (such as variable, function, or label names).
You can find a list of these keywords in “About reserved words” on page 139.