MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 20

Actionscript language reference
Table of Contents

Advertisement

You can also use methods of the built-in Math and Number classes to manipulate numbers. For
more information on the methods and properties of these classes, see the
"Number class"
The following example uses the
square root of the number 100:
Math.sqrt(100);
The following example traces a random integer between 10 and 17 (inclusive):
var bottles:Number = 0;
bottles = 10 + Math.floor(Math.random()*7);
trace("There are " + bottles + " bottles");
The following example finds the percent of the
an integer:
var percentLoaded:Number = Math.round((intro_mc.getBytesLoaded()/
intro_mc.getBytesTotal())*100);
Boolean data type
A Boolean value is one that is either
and
to 1 and 0 when appropriate. Boolean values are most often used with logical
false
operators in ActionScript statements that make comparisons to control the flow of a script.
The following example checks that users enter values into two TextInput component instances.
Two Boolean variables are created,
variables evaluate to
//Add two TextInput components and one Button component on the Stage
//Strict data type the three component instances
var userName_ti:mx.controls.TextInput;
var password_ti:mx.controls.TextInput;
var submit_button:mx.controls.Button;
//Create a listener object, which is used with the Button component
//When the Button is clicked, checks for a user name and password
var btnListener:Object = new Object();
btnListener.click = function(evt:Object) {
//checks that the user enters at least one character in the TextInput
//instances and returns a Boolean true/false.
var userNameEntered:Boolean = (userName_ti.text.length>0);
var isPasswordCorrect:Boolean = (password_ti.text == "vertigo");
if (userNameEntered && isPasswordCorrect) {
var titleMessage:String = "Welcome "+userName_ti.text+"!";
}
};
submit_button.addEventListener("click", btnListener);
For more information, see
on page
36.
20
Chapter 1: ActionScript Basics
entries.
sqrt()
true
userNameEntered
, a welcome message is assigned to the
true
"Using built-in functions" on page 41
(square root) method of the Math class to return the
movie clip loaded and represents it as
intro_mc
or
. ActionScript also converts the values
false
and
isPasswordCorrect
"Math class"
, and if both
String variable.
titleMessage
and
"Logical operators"
and
true

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX-FLEX ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

This manual is also suitable for:

Flex

Table of Contents