Requesting Variable Type

Requesting Variable Type

Flash CS4 ActionScript 3.0 Tutorial

 

How to View Flash ActionScript Variable Data Type

 

 

Variables are assigned a specific data type. Some of the variable options are, String (letters and numbers), Boolean (true or false), Number (numbers with decimal places), int (whole numbers) or uint (positive whole numbers). Using this technique, you can query the data type for any variable or instance.

For more information about variables, see topics, Defining a Variable, Interpreting a Number as a String and Interpreting a String as a Number.

 

Step One

Option double-click (PC - Alt double-click) the first keyframe of a new blank document to open the ActionScript panel.

Step Two

Add the following code to establish several variables with different data types.

var var01:Array=new Array();

var var02:Boolean=false;

var var03:String="games";

var var04:int=-2;

var var05:Number=3.5

var var06:uint=5

trace("Array = " + typeof(var01));

trace("Boolean = " + typeof(var02));

trace("String = " + typeof(var03));

trace("int = " + typeof(var04));

trace("Number = " + typeof(var05));

trace("uint = " + typeof(var06));

Step Three

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). The variable type is listed for each variable in the Output panel.

Why the trace() Statement?

In each of these examples we also included the trace statement. The trace statement allows you to see the variable type in the Flash Output panel whenever you run the script.