Flash CS4 ActionScript 3.0 Tutorial


How to Create a Variable with True or False States Using Flash ActionScript



Boolean variables can be set to one of two states, true or false. They are handy when working with conditional statements. For instance, you may want to know if two values are equal. If so, then another operation is performed. In this example, the values are compared. If they are equal, then the Boolean variable becomes true. Boolean values can also be converted back and forth between a Number or int variable.


Step One

Open a new document and name the default layer, Actions.

Step Two

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

Step Three

Copy/Paste the following code in the ActionScript Panel:

var bolValue:Boolean=false;

var intValue:int=1;

trace("Initial Boolean Value = " + bolValue);


trace("Integer Value of Boolean false = " + intValue);



trace("New Boolean Value = " + bolValue);

Step Four

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). The trace statements appear in the Output panel.

Dissecting the Code

The first two lines establish two new variables named bolValue and intValue. The first is a Boolean and the other is an int variable. The next line traces the current value of bolValue in the Output panel.

Lines four and five convert the false value of bolValue to an integer. That value is then displayed in the Output panel.

Line six adds one to intValue to make the value true.

Finally the intValue of one is converted back to a boolean value of true and is displayed in the Output panel. career skills