Chapter 6. Basic Data Exchange

[ LiB ]  


In the preceding chapter, you learned ways to structure, manage, process, and manipulate complex data. This chapter covers basic ways to both import and export data. Chapters up to this point have covered how to deal with data after it's inside Macromedia Flash MX 2004. But from where does the data originate? For example, you may want to import up-to-the-minute news from an outside source such as another web site. Actually, the data source need not be on the other side of the world. You can import data stored in a simple text file, thus eliminating the need to open Flash for every minor change. (Just edit the text file.)

Another way to exchange data is to save it. Sometimes you'll change data after it arrives inside Flash (for instance, the user adds to an array), in which case you may want to save those changes. If a user changes data, it needs to be exported from the Flash file so that you can import it again next time the app runs (perhaps to let the user pick up where he left off). (Remember, variables will naturally vanish if you don't export them for safekeeping.)

It turns out there are many different protocols for importing and exporting data. This chapter covers data exchange methods that require no more than Flash, a browser, and a simple text-editing program. (In later chapters, you'll learn ways to incorporate application servers, databases, web services, and the Flash Communication Server.)



A protocol is more than a way of sending and receiving data. It's the entire process of how the data is formatted, how it travels , and how it's processed when receivedall necessary to ensure successful data exchange. For example, think of the protocol for sending a package: It's the entire process of wrapping it, attaching a label, paying for land or air stamps, getting the recipient's signature, and, finally, the opening of the package with a box cutter .

Specifically, this chapter covers the following topics:

  • The local shared object, which enables you to write variables to the user's disk and then later read the values

  • The local connection object for letting one app trigger events in another app

  • The LoadVars object to import and export data in flat URL-encoded form, including text files and conventional application servers

  • The XML object to import and export structured data

You'll see that many of the objects covered in this chapter are variations of the same thing. However, each is suited for a particular task. For creating files on the users' machine so that you can read them back the next time they visit your app, use local shared objects. For sending messages between more than one Flash app, use local connection. Both LoadVars and the XML object are similar in that they can read data (from disk or an application server) and write data (to an application server). They differ in the format of that data. The simple name /value pairs supported by LoadVars is fine for certain data, but when your data is more complex you will want to use the XML format.

Ultimately, these are all basic ways to exchange data. Don't let that discount the fact they're all very useful. We just don't cover Flash Remoting, data components , and the new support for the Simple Object Access Protocol (SOAP) until next chapter. Also, realize the foundation skills you learn using the local shared object and local connection objects will apply directly to learning how to use their remote counterparts in Chapter 8, "Foundation Communication Server," and Chapter 9, "Advanced Communication Server."

[ LiB ]  

Macromedia Flash MX 2004 for Rich Internet Applications
Macromedia Flash MX 2004 for Rich Internet Applications
ISBN: 0735713669
EAN: 2147483647
Year: 2002
Pages: 120 © 2008-2017.
If you may any questions please contact us: