Detailed instructions for use are in the User's Guide.
[. . . ] Learning Flash Lite 1. X ActionScript
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 either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be registered in certain jurisdictions including internationally. [. . . ] 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.
12
Flash 4 ActionScript Primer
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. For example, the following ActionScript calls the code located on the frame labeled moveUp:
call("moveUp");
The call() function operates synchronously; any ActionScript that follows a call() function call won't execute until all of the ActionScript on the specified frame finishes executing.
To call ActionScript on another frame:
1.
In a new Flash document, insert a keyframe on Frame 10.
2.
With the new keyframe selected, open the Actions panel (Window > Actions), and type the following code:
trace("Hello from frame 10");
3.
Select the keyframe on Frame 1, and in the Actions panel, type the following code:
stop(); call(10);
This code stops the playhead on Frame 1, and then calls the code on Frame 10.
4.
Test the application in the emulator and open the Output panel (Window > Output). You should see "Hello from frame 10" displayed in the Output panel.
Using the call() function to create functions
13
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. A call clip contains a keyframe for each function you want to create. You typically label each keyframe according to its purpose. Macromedia also recommends that you create a new layer for each new keyframe, and that you give each layer the same name as the frame label you assign to the keyframe. The following figure shows the Timeline of an example call clip. The first keyframe of a call clip always contains a stop() action, which ensures that the playhead doesn't continually loop over the frames in its Timeline. Subsequent keyframes contain code for each "function. " Each function keyframe is labeled to identify what it does. To make editing and viewing the call clip easier, each function keyframe is typically inserted on a separate layer.
First keyframe contains stop() action
Frame labels Each keyframe contains code.
The following procedure explains how to create and use a call clip.
To create and use a call clip:
1. 3.
In Flash Professional 8, create a new document from the Flash Lite 1. 1 Symbian Series 60 document template. In the Create New Symbol dialog box, type Call Clip in the Name text box, and then click OK. The movie clip opens in editing mode.
14
Flash 4 ActionScript Primer
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. 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:
5.
6. 8.
Select the keyframe on the Actions layer and open the Actions panel. [. . . ] To load these types of media, you need to convert the image data to the SWF file format. You can do this "manually" with the Flash authoring tool by importing the image file into a new document, and then exporting the file to a Flash Lite or Flash 4 SWF file. There are also third-party utilities that can perform this type of conversion for you automatically.
For more information about loading SWF files, see loadMovie() in Flash Lite 1. x ActionScript Language Reference.
Loading external data
To load external data into a Flash Lite application, you use the loadVariables() function. You can load data over the network (from an HTTP address) or from the local file system. [. . . ]