About strings and the String class
463
To compare strings to other data types:
1.
Create a new Flash document and save it as
comparenum.fla
.
2.
Add the following ActionScript to Frame 1 of the main Timeline:
var myStr:String = "4";
var total:Number = 4;
if (myStr == total) {
trace("Types are converted.");
}
3.
Save the Flash document and select Control > Test Movie to test the SWF file.
When comparing two different data types (such as strings and numbers), Flash tries to
convert the data types so that a comparison can be made.
Use the strict equality (
===
) and strict inequality (
!==
) operators to verify that both
comparison objects are of the same type. The following example uses strict comparison
operators to ensure that Flash doesn’t try to convert data types while trying to compare values.
To force strict data type comparisons:
1.
Create a new Flash document and save it as
comparestrict.fla
.
2.
Add the following ActionScript to Frame 1 of the main Timeline:
var str1:String = "4";
var str2:String = "5";
var total:Number = 4;
if (str1 !== total) {
trace("Types are not converted.");
}
if (str1 !== str2) {
trace("Same type, but the strings don't match.");
}
3.
Save the Flash document and select Control > Test Movie.
For more information on using operators with strings, see
“About using operators with
strings” on page 182
.
You can find a sample source file, strings.fla, in the Samples folder on your hard disk. This file
shows you how to build a simple word processor that compares and retrieves string and
substring selections.
■
In Windows, browse to
boot drive
\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Strings.
■
On the Macintosh, browse to
Macintosh HD
/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Strings.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...