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 certain 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 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). Once this text string has been loaded, Flash will automatically break it into its respective variable name-values, making them available for use as any other variables. As you can see, an equals sign is used to associate a variable name with its value, while an ampersand (&) marks the end of one variable and the beginning of another. The format supports an unlimited number of variables. Keep in mind, however, that only simple variables can be stored in this format; data contained in objects, arrays, or any other data type cannot. You will use this format in an exercise later in this lesson.

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

     <States>    <State>      <Name>North Carolina</Name>      <Capital>Raleigh</Capital>    </State>    <State>      <Name>Virginia</Name>      <Capital>Richmond</Capital>    </State>  </States> 

    Once an XML document is loaded into Flash, a script (which you must write) is used to extract information from it.

    NOTE

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


  • Shared objects. We'll describe these in detail later in this lesson; for now, just understand that shared objects are like Flash cookies: They allow you to store objects (data) locally, on the user's hard drive. This means that once 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 in turn means that 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 arrays, XML objects, even custom objects. You can make this process of saving data transparent to users, or you can provide buttons for them to initiate the action. And you can have multiple shared-object data files on a single computer because each movie usually (though not always) creates its own data file.

Now that you're familiar with the various data formats 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 above. Text files can be loaded using loadVariables() or the load() method of the LoadVars object, both of which we'll discuss later in this lesson. You can easily create these types of data sources using Windows Notepad or Apple SimpleText.

  • Server-side scripts. These are scripts placed on ASP, CFM, 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. Imagine, for example, 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 format and the URL string format which means that by communicating with a page that contains a server-side script, Flash can load dynamic data created on the fly.

    graphics/11fig02.gif

  • 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 servers including how to build a chat application with them in Lesson 12.)

  • Shared objects. As mentioned above, shared objects are used to create data files that store information on a user's hard drive which you can then retrieve and build back into a movie (as you will see in the last exercise in this lesson).

TIP

Flash has a security feature that prevents you from loading data across domains. For example, if you were to upload a movie to www.site1.com and attempt to load data from www.site2.com, your load would fail.




Macromedia Flash MX ActionScripting Advanced. Training from the Source
Macromedia Flash MX ActionScripting: Advanced Training from the Source
ISBN: 0201770229
EAN: 2147483647
Year: 2002
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net