As with any Flash application, chances are that you'll be using some amount of ActionScript in your content to build in interactivity or control certain behaviors. Because ActionScript for Flash Lite 1.1 is based on the Flash 4 ActionScript code base, there are certain limitations to be aware of when developing content.
In general, Flash Lite 1.1 adheres to Flash 4 ActionScript notation, but it also uses some Flash 5 notation. Being able to understand when and where you have to use Flash 4 ActionScript is critical when developing applications. Because Flash Lite 1.1 uses Flash 4 ActionScript, you have to know how to refer to Timelines and variables using the slash and colon syntax.
To specify a path to a Timeline, use slash syntax (/) combined with dots (..) to build the path reference. You can also use _level0 or _root from Flash 5 notation.
Example 1: Targeting the movie clip cards from the main Timeline
tellTarget("/box/cards")
tellTarget("_level0/box/cards")Example 2: Targeting the main Timeline from a movie clip cards
tellTarget("../../cards")
tellTarget("_root")Example 3: Referring to the parent movie clip of cards
tellTarget("../cards")
tellTarget("../cards")To specify a variable on a Timeline, use slash syntax (/) combined with dots (..) and colons (:). You can also use the Flash 5 dot notation.
Example 1: Variable car on the main Timeline
/:car _root.car
Example 2: Variable car in a movie clip instance that resides on the main Timeline
/mc1/mc2/:car _root.mc1.mc2.car
Example 3: Variable car in a movie clip instance that resides on the current Timeline
mc2/:car mc2.car
Arrays are very useful for creating and manipulating ordered lists of information, usually variables and values. Unfortunately Flash Lite 1.1 does not support the array() constructor, so you must emulate the creation of an array to reference throughout the application. This is referred to as a pseudo-array.
For example, let's say you created the following ActionScript variables:
color_1 = "orange"; color_2 = "green"; color_3 = "blue"; color_4 = "red";
To dynamically access the elements in this pseudo-array, you could use the following ActionScript code:
for (i = 1; i <=4; i++) {
trace (eval ("color_" add i));
}You can use Timeline-based loops for executing a block of code repeatedly, which can be useful for creating movement or acting as a timer. For example, if you wanted to move a movie clip from the top of the Stage to the bottom, you could use a simple motion tween or you could do it with ActionScript.
With ActionScript it would look something like this:
// code on frame 10
for (i = 0; i < 30; i++)
headline_mc._y += 5;
}
// code on frame 11
gotoAndPlay(10);
add Operator Instead of the & OperatorWhenever you want to concatenate variables or text strings, you must use the add operator
instead of the & operator. Because most developers are not
familiar with using the add operator, they often experience problems
when testing content. This is usually the culprit.
Example 1: Correct way
headline = ("Oil prices reach" add " all time high");Example 2: Incorrect way
headline = ("Oil prices reach" & " all time high");eq and = =When using a conditional statement such as if(), you're usually comparing two values to check for equality. The equality operator == is used to compare numbers, strings, and other data types, while the string equality operator eq is
used only to compare string values. It's good practice just to use the == operator in conditional statements to avoid having to decide which operator to use.
Example 1: Correct way
if (_root.game == "1"){
play();
}Example 2: Incorrect way
if (_root.game eq "1"){
play();
}keyPress EventsSimply put, you can only use keyPress events to check when a
user presses a key on the handset. You can only assign these to buttons, so
it's a good idea to put all of your keyPress events into one button
that's offstage to help organize your code.
Example:
on (keyPress "<Enter>") {
gotoAndPlay("menu");
}Here's a complete list of all of the supported keyPress events:
keyPress "<Up>"keyPress "<Down>"keyPress "<Left>"keyPress "<Right>"keyPress "<Enter>"keyPress "0" (0–9 can be used)keyPress "*"keyPress "#"keyPress "<PageDown>"keyPress "<PageUp>"Movie clip events—such as onEnterFrame(), onKeyDown(), onUnload(),
and others—are not supported by Flash Lite 1.1, and you should not use
them. If you do, you'll get warning messages in the authoring
environment when you run a Test Movie command.
call() InsteadOne big drawback to remember is that you cannot use functions in Flash Lite
1.1 content. The workaround is to use the deprecated call() function
instead. It's pretty straightforward and easy to use.
Example:
// custom AS code on a frame labeled "buttonAction"
if (_root.object == "help") {
gotoAndStop("helpSection");
} else if (_root.object == "extras") {
gotoAndStop("extrasSection");
}
// AS code for help button
on(keyPress "8") {
_root.object = "help";
call("buttonAction");
}For a complete list of all supported Flash Lite 1.1 ActionScript commands, refer to Appendix A in the Macromedia Flash Lite 1.1 Authoring Guidelines.