Understanding Data Sources and Data Formats

A data source is a place from which Flash can load external data (that is, data not directly programmed into the movie). For example, Flash can load data from a simple text file, and that text file is considered a data source. Data transfer is the act of retrieving data from a source or sending data from Flash to another application. In this section, you'll learn about the different types of data sources as well as the Flash objects and methods used to communicate with these sources in the data transfer process.

Any data that you plan to load into Flash from an external source must be structured (formatted) in a specific way. Flash supports the following formats:

  • URL string. In this type of name/value pair formatting, variables and their values are defined as a string of text. For example, the following text string:

    name=Jobe&website= http://www.electrotank.com&hairColor=brown

    defines three variables (name, website, hairColor) and their respective values (Jobe, http://www.electrotank.com, brown). After this text string has been loaded, Flash automatically breaks it into its respective variable names/values, making them available for use just as any other variables. An equals sign (=) is used to associate a variable name with its value and an ampersand (&) marks the end of one variable and the beginning of another. You will use this format in an exercise later in this lesson. The format supports an unlimited number of variables. Only simple variables can be stored in URL string format; data contained in objects, arrays, or any other data type is not supported by a string of text.

  • XML. This popular formatting standard allows data to be stored in a logical structure. For example:

        <Name>North Carolina</Name>

After an XML document is loaded into Flash, a script that you write is used to extract information from the XML document.


See Lesson 12, "Using XML with Flash," for more information on the XML format.

  • Shared objects. These will be discussed later in this lesson; for now, understand that shared objects are similar to Flash cookies: shared objects allow you to store objects (data) locally on the user's hard drive. This means that after a user views and exits a Flash movie (as a projector or online), the data created while the movie was playing (user's name, last section visited, and so on) is saved. This data can be retrieved the next time the user plays the movie on the same computer. By using shared objects, you can store not only variables and their values, but any kind of data object, including arrays, XML objectseven custom objects. You can make this process of saving data transparent to users, or you can provide buttons for them to initiate the action. You can also have multiple shared-object data files on a single computer because each movie usually creates its own data file.

Now that you're familiar with the various data formats that Flash supports, let's review the sources from which Flash can load data:

  • Text files. Flash can load text files (*.txt) containing data formatted using the URL string format mentioned earlier in this lesson. Text files can be loaded using loadVariables() or the load() method of the LoadVars class, both of which we'll discuss later in this lesson. You can easily create these types of data sources using Windows Notepad or Apple Simple Text.

  • Server-side scripts. Server-side scripts are placed on ASP, CFML, CGI, or JSP pages and executed by a server. Although invisible to the user, the scripted page actually generates formatted data (HTML, XML, and so on) that's sent back to the requesting source. For example, imagine visiting a page called news.asp that contains a server-side script, and probably no real content. The script, which is executed when a user visits the page, is used to dynamically generate and send to the user's browser an HTML-formatted page containing the latest news (probably extracted from a database). Server-side scripts can return data in both the XML and URL string formats. This means that by communicating with a page containing a server-side script, Flash can load dynamic data created on the fly.


  • XML files. An XML file is simply a text file that contains XML-formatted data; such files usually include an xml extension.

  • XML socket. Socket servers are applications that run on a server and connect several simultaneous users to one another. Flash can send or receive information via the socket using the XML format. (You'll learn more about socket serversincluding how to build a chat application with themin Lesson 12, "Using XML with Flash.")

  • Shared objects. As already mentioned, shared objects are used to create data files that store information on a user's hard drive. You can then retrieve these files for use with a movie, as you will see in the last exercise in this lesson.