Learning Flash Lite 1.
Trademarks 1 Step RoboPDF, ActiveEdit, ActiveTest, Authorware, Blue Sky Software, Blue Sky, Breeze, Breezo, Captivate, Central, ColdFusion, Contribute, Database Explorer, Director, Dreamweaver, Fireworks, Flash, FlashCast, FlashHelp, Flash Lite, FlashPaper, Flash Video Endocer, Flex, Flex Builder, Fontographer, FreeHand, Generator, HomeSite, JRun, MacRecorder, Macromedia, MXML, RoboEngine, RoboHelp, RoboInfo, RoboPDF, Roundtrip, Roundtrip HTML, Shockwave, SoundEdit, Studio MX, UltraDev, and WebHelp are eith
Contents Chapter 1: About Flash Lite 1.x ActionScript . . . . . . . . . . . . . . . . . . 5 Flash Lite 1.x ActionScript overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Differences between Flash Lite 1.0 and Flash Lite 1.1 ActionScript . . . 6 Flash 4 ActionScript not supported by Flash Lite 1.x ActionScript. . . . 6 Features not available in Flash Lite 1.x ActionScript . . . . . . . . . . . . . . . . 7 Chapter 2: Flash 4 ActionScript Primer. . . . . . . . . . . . . . . . . . . . . .
Contents
CHAPTER 1 1 About Flash Lite 1.x ActionScript You use ActionScript to add programming logic and interactivity to your Macromedia Flash Lite applications. The version of ActionScript in Flash Lite 1.0 and 1.1—referred to collectively as Flash Lite 1.x ActionScript—is a hybrid of Flash 4 ActionScript, plus additional commands and properties specific the Flash Lite player, such as the ability to initiate phone calls or text messages, or get time and date information from the device.
fscommand2() function Like the fscommand() function, you use fscommand2() to communicate with the host environment or system—in this case, the mobile phone or device. The fscommand2() function provides enhancements to fscommand(), including the ability to pass an arbitrary number of arguments and to retrieve immediate return values (rather than having to wait until the next frame, as with fscommand()). Differences between Flash Lite 1.0 and Flash Lite 1.1 ActionScript The following Flash Lite 1.
■ The _soundBufTime property. ■ The _url property. ■ The String() conversion function. Features not available in Flash Lite 1.x ActionScript Because Flash Lite player is based on an older version of Flash Player, it does not support all the programming features available in more recent releases of Flash Player or other programming languages that you might be familiar with. This section discusses programming features not available in Flash Lite 1.
About Flash Lite 1.
2 CHAPTER 2 Flash 4 ActionScript Primer Flash Lite 1.x ActionScript is based on the version of ActionScript that was first available in Flash Player 4. Consequently, several programming features available in later versions of Flash Player (for desktop systems) are not available to Flash Lite 1.x applications.
The setProperty() function lets you set a property of a movie clip instance, as shown in the following example: setProperty(cartoonArea, _x, 100); The following example is equivalent to the previous example but uses dot syntax: cartoonArea._x = 100; You can also get or set movie clip properties from within a tellTarget() statement.
Using variables To specify a variable on a timeline, use slash syntax (/) combined with dots (..) and colons (:). You can also use the dot notation. The following code refers to the car variable on the main timeline: /:car _root.car The following example shows the car variable in a movie clip instance that resides on the main timeline: /mc1/mc2/:car _root.mc1.mc2.car The following example shows the car variable in a movie clip instance that resides on the current timeline: mc2/:car mc2.
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.
Using the call() function to create functions You can’t define or call custom functions in Flash Lite as you can in Flash Player 5 and later. However, you can use the call() ActionScript function to execute code that resides on an arbitrary frame in the timeline. This technique lets you encapsulate commonly used code in a single location, making it easier to maintain. The call() function takes a frame number or frame label as a parameter.
You can also call code that resides on another timeline, such as a movie clip’s timeline. To execute the code, specify the movie clip instance name followed by a colon, and then the frame number or label. For example, the following ActionScript calls the code that resides on the frame labeled moveUp in the movie clip instance named callClip: call("callClip:moveUp"); This technique is often used to create call clips or function clips—movie clips whose sole purpose is to encapsulate regularly used code.
4. Click the Add New Layer button the Timeline window twice to insert two new layers. Name the top layer Actions, the second layer function1, and the third layer function2. 5. Insert a keyframe on Frame 2 of the function1 layer, and another keyframe on Frame 3 of the function2 layer, as the following figure shows: 6. Select the keyframe on the Actions layer and open the Actions panel. 7. Add a stop() action to the Actions panel. 8.
11. Set your document’s view to include the work area around the Stage by selecting View > Work Area. Because the call clip doesn’t need to be visible to the user, you can place it in the work area. 12. Open the Library panel (Window > Library) and drag the Call Clip symbol to the work area around the Stage. The call clip doesn’t contain any visual elements so it appears on the Stage as a small circle, representing the movie clip’s registration point.
Using the eval() function The eval() function lets you dynamically reference variables and movie clip instances at runtime. The eval() function takes a string expression as a parameter and returns either the value of the variable represented by that expression or a reference to a movie clip.
Flash 4 ActionScript Primer
3 CHAPTER 3 Common Scripting Tasks This chapter discusses common Flash Lite scripting tasks for working with the user’s device. These include, for example, getting device capability information, initiating phone calls and text messages, and determining network status. This chapter contains the following topics: Determining device and platform capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Opening a web page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Typically, you use capability variables to determine if a device supports a specific feature before attempting to use that feature. For example, suppose that you wanted to develop an application that downloads data from a web server using the loadVariables() function. Before attempting to load the data, you can first check the value of the _capLoadData variable to determine if the device supports that feature, as follows: if(_capLoadData == 1) { loadVariables("http://www.macromedia.com/data.
The following code attempts to initiate call to 555-1212: getURL("tel:555-1212"); Flash Lite only processes one getURL() action per frame or per event handler. Certain handsets restrict the getURL() action to keypress events only, in which case the getURL() call is processed only if it is triggered within a keypress event handler. Even under such circumstances, only one getURL() action is processed per keypress event handler.
Initiating an e-mail message You can use Flash Lite to initiate an e-mail message. To initiate an e-mail message, you use the getURL() command and pass it the mailto: protocol, followed by the recipient’s e-mail address. You can optionally specify the message subject and body in the URL’s query string, as follows: getURL("mailto:mobile-developer@macromedia.com?subject=Flash Lite"); To specify just the message body in the query string, use the following code: getURL("mailto:mobile-developer@macromedia.
This example assumes that the data file and the SWF are both located in the same folder, either on your computer (when you test in the emulator) or on the device’s memory card (when you test on an actual device). To test the application on the device, you must do one of the following: ■ Transfer the text file to your device and put it in the same folder as the SWF file. ■ Post the text file to a URL on a web server (for example, www.your-server.com/data.txt).
5. Select the first (top-most) text field, and in the Property inspector, type item_1 in the Var text box. This variable name corresponds to the name of the first variable defined in the data.txt file you created previously (item_1=Hello). 6. In the same manner as described in the previous two steps, give the remaining four text fields the variable names item_2, item_3, item_4, and item_5. 7. Shift-select each text field so that they’re all selected, and select Modify > Convert To Symbol. 8.
Index A L arrays, emulating with strings 11 load external data 22 load external SWF files 22 loadMovie() function, using 22 loadVariables() function, using 22 C call() function, using 13 concatenate strings 12 M e-mail message, starting 22 eval() function, using 17 movie clips getting and setting properties 9 referencing dynamically 17 multimedia message, starting 21 F O Flash Lite 1.x ActionScript differences between 1.0 and 1.
V variables dot syntax and slash syntax 11 referencing 11 referencing dynamically 17 W web page, opening 20 26 Index