Game Development Reference
In-Depth Information
var yesOrNo:Boolean = false;
trace("Value of anInteger: " + anInteger);
trace("Value of aNumber: " + aNumber);
trace("Value of aString: " + aString);
trace("Value of yesOrNo: " + yesOrNo);
}
}
}
To print the values of variables, we can use the global function trace . The trace takes
a string as a parameter. AS3 also allows you to concatenate the string and other types
using the + operator as you can see in the listing.
To run the project in debug mode, click on the little icon with the green bug in the
tool bar. Remember, you can see that the output of trace function calls only when
you run the project in debug mode.
When the project is run in debug mode, the browser is launched with an empty gray
window. This is because we are not drawing anything to the screen yet. You will
need to switch back to the Flash Builder and inspect the Console tab view, which
appears at the bottom of the Flash Builder window.
You should see the following:
Value of anInteger: 3
Value of aNumber: 3.1415
Value of aString: This is a string.
Value of yesOrNo: false
Here is a code snippet to work with an Array datatype:
var anArray:Array = new Array();
anArray.push("Element 1");
anArray.push("Element 2");
anArray.push("Element 3");
var i:int;
for ( i=0; i<anArray.length; i++) {
trace("Element in the array at index " + i +
" has a value of " + anArray[i]);
}
This will produce the following output:
Element in the array at index 0 has a value of Element 1
Element in the array at index 1 has a value of Element 2
Element in the array at index 2 has a value of Element 3
 
Search WWH ::




Custom Search