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. This feature is available only in Flash Lite 1.1 and later.

This section demonstrates how to use the loadVariables() function to load data from an external file and display that data in dynamic text fields. First you'll create the data file, a text file that contains five name-value pairs separated by ampersand (&) symbols. Then you'll create the Flash Lite application that loads and displays the data contained in the text file.

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:

To create the data file:

  1. Using a text editor (for example, Notepad or SimpleText), create a file that contains the following text:
    item_1=Hello&item_2=Bonjour&item_3=Hola&item_4=Buon+giorno&item_5=G'day
    
  2. Save the file as data.txt.

To create the Flash Lite application to load the data:

  1. Create a new document from the Flash Lite 1.1 Symbian Series 60 document template.

    For more information about using Flash Lite document templates, see Using Flash Lite document templates in Getting Started with Flash Lite 1.x.

  2. Save the file as dataloading.fla to the same folder that contains the text file (data.txt) that you created previously.
  3. In the Timeline, select Frame 1 of the layer named Content.
  4. Using the Text tool, create five dynamic text fields on the Stage, as the following figure shows:

  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. In the Convert to Symbol dialog box, select Movie Clip as the symbol type and click OK.
  9. Select the movie clip you just created and, in the Property inspector, type data_clip in the Instance Name text box.
  10. In the Timeline, select Frame 1 of the Actions layer and open the Actions panel (Window > Actions).
  11. Type the following code in the Actions panel:
    loadVariables("data.txt", "data_clip");
    
  12. Save your changes (File > Save) and test the application in the emulator (Control > Test Movie).

    You should see each text field populated with the data in the text file, as the following figure shows: