Declare an integer variable and assign it a value of 21 with the AS3 "int" object declaration statement:
var A: int = 21
Perform multiplication with integers with the multiplication operator, *, division with the division operator, /, subtraction with the subtraction operator, -, and addition with the addition operator, +. Use the equals operator, =, to evaluate an integer algebraic expression.
Assign an integer expression in AS3 to store the sum of two integers, 5 and 3, and divide them by the minuend of two integers (4 and 2) with the expression:
A = (5+3)/(4-2);
Display the value of the integer variable, A, in the output panel with the AS3 trace method.
trace (A);
Use the int method to convert decimal numbers that are not integers, such as decimal numbers like 3.14 and 3.89, to an integer number with the AS3 code statements below. Display the integer results "3, 3" with the trace command.
var i1:int = new int(3.14)
var i2:int = new int(3.87):
trace (i1, i2);
Store decimal numbers in integer variables to automatically round the decimal number down. Use the AS3 code statement var myint: int = 3.8. to store the integer value 3 in the myint integer variable.
Use decimal numbers in an arithmetic expression to automatically convert all the numbers in the expression to integers and store the integer calculation result as an integer. Use the myint integer variable within the arithmetic expression "myint = 3.2 / 1.5" to perform a rounded down division equivalent to "myint = 3/1" which produces an integer value of 1.
Convert text representation of numbers in String variables to integer numbers with the int method and then perform integer math calculations with them. Use the AS3 code below to convert the text "220" to an integer number and add 1 to 220 to display the integer result 221.
var textstring: String = "220"
var myint:int = new int(textstring);
trace(myint);
myint = myint + 1;
trace (myint);