About data types
75
Boolean data type
A Boolean value is one that is either
true
or
false
. ActionScript also converts the values
true
and
false
to
1
and
0
when appropriate. Boolean values are most often used with logical
operators in ActionScript statements that make comparisons to control the flow of a script.
The following example loads a text file into a SWF file, and displays a message in the Output
panel if the text file does not load correctly, or the parameters if it does load successfully. See
the comments in the code example for more details.
var my_lv:LoadVars = new LoadVars();
//success is a Boolean value
my_lv.onLoad = function(success:Boolean) {
//if success is true, trace monthNames
if (success) {
trace(my_lv.monthNames);
//if success is false, trace a message
} else {
trace("unable to load text file");
}
};
my_lv.load("http://www.helpexamples.com/flash/params.txt");
The following example checks that users enter values into two TextInput component
instances. Two Boolean variables are created,
userNameEntered
and
isPasswordCorrect
,
and if both variables evaluate to
true
, a welcome message is assigned to the
titleMessage
String variable.
// Add two TextInput components, a Label, and a 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;
var welcome_lbl:mx.controls.Label;
//Hide the label
welcome_lbl.visible = false;
// 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 + "!";
welcome_lbl.text = titleMessage;
Summary of Contents for FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Page 1: ...Learning ActionScript 2 0 in Flash...
Page 8: ...8 Contents...
Page 18: ...18 Introduction...
Page 30: ...30 What s New in Flash 8 ActionScript...
Page 66: ...66 Writing and Editing ActionScript 2 0...
Page 328: ...328 Interfaces...
Page 350: ...350 Handling Events...
Page 590: ...590 Creating Interaction with ActionScript...
Page 710: ...710 Understanding Security...
Page 730: ...730 Debugging Applications...
Page 780: ...780 Deprecated Flash 4 operators...
Page 830: ...830 Index...