MACROMEDIA FLASH 8-LEARNING FLASH LITE 1.X ACTIONSCRIPT Manual - page 12
12
Flash 4 ActionScript Primer
In addition to letting you reference existing variables, you can also use the
eval()
function on
the left side of a variable assignment to create variables at runtime. For example, suppose you
want to maintain a list of high scores as a user plays a game. Each time the user completes a
turn, you add their score to the list:
eval("highScore" add scoreIndex) = currentScore;
scoreIndex++;
Each time this code executes, it adds a new item to the list of high scores and then increments
the
scoreIndex
variable, which determines each item’s index in the list. For instance, you
might end up with the following variables:
highScore1 = 2000
highScore2 = 1500
highScore3 = 3000
Working with text and strings
Flash Lite provides some basic ActionScript commands and properties for working with text.
You can get and set the values of text fields, concatenate strings, URL-encode or URL-decode
text strings, and create scrolling text fields.
This section contains the following topics:
■
“Concatenating strings” on page 12
■
“Scrolling text” on page 12
Concatenating strings
To concatenate strings in Flash Lite, you use the
add
operator, as the following example
shows:
city = "Boston";
team = "Red Sox";
fullName = city add " " add team;
// Result:
// fullName = "Boston Red Sox"
Scrolling text
You can use the
scroll
property of dynamic and input text fields to get or set the field’s
current scroll position. You can also use the
maxscroll
position to determine a text field’s
current scroll position relative to the maximum scroll position. For an example of how to
create a scrolling text field, see “Creating scrolling text (Flash Professional Only)” in
Developing Flash Lite Applications.