Chapter 19. Using Data

There was a time when Flash was used exclusively for timeline-based animations. However, many current Flash applications—even simple ones—load and send data to and from external resources. For example, a simple web site built in Flash might display news. In order to keep the news fresh, it’s important to be able to load the text from an external resource, such as a text file or from a PHP page that retrieves the data from a database. If you have a comments form, you’ll need to send data to a script. There are many potential uses of such data in Flash applications.

To work with data most effectively, you’ll need to use ActionScript. In a few cases, the ActionScript will be relatively simple. For example, if you want to load variables from an external resource, the solution involves ActionScript as discussed in Recipe 19.1. However, there are also mechanisms for working with data in basic ways that do not require ActionScript. In this chapter, you’ll read about solutions that use simple and/or minimal ActionScript. Non-ActionScript solutions are discussed where appropriate.

19.1. Loading Variables

Problem

You want to load variables at runtime.

Solution

Use a LoadVars object. Call the load( ) method.

Discussion

There are many reasons you might want to load variables at runtime. Loading variables at runtime makes applications more dynamic than they would be if you had to hardcode all values into the file. For example, if your application displays a new quote or snippet ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.