Chapter 8: Using the Data Components with XML

In Chapter 4, you saw how to use ActionScript with the XML class. We loaded an XML document into Flash. We also created and modified XML content within Flash and sent it to a server-side file for processing. In Chapters 5, 6 and 7, we used Office 2003 for the PC to generate and manage the XML content for use in Flash.

Instead of writing ActionScript to work with XML content, you can use the data components supplied with Flash Professional. These components allow you to work visually. You drag the components into your movies and configure them using the Component Inspector panel. This can speed up your development processyou can include XML content without having to write a single line of ActionScript. The data components have no visual appearance in the published .swf file, so it doesnt matter where you place them.

Understanding Data Components

Flash Professional 8 includes a number of data components. Table 8-1 lists and explains the main purpose of each one.

Table 8-1: The data components shipped with Flash Professional

Component

Purpose

DataHolder

The DataHolder stores data and can be used to share information between other components. Unlike the DataSet, it doesnt track changes made by UI components.

DataSet

The DataSet also stores data that you can share with other components. The DataSet allows you to keep track of modifications that you make using UI components. You can then notify external applications of the changes made within Flash. Well learn more about the DataSet component later in this chapter.

RDBMSResolver

The RDBMSResolver sends changes in data to an external data source. It works with database content.

WebServiceConnector

The WebServiceConnector consumes SOAP web services. Youll find out more about this component in Chapter 9.

XMLConnector

The XMLConnector connects to external XML documents. You can use the component to read and write XML data. You can use the component with the DataSet and XUpdateResolver components where you need to change external data using a server-side page. Well learn more about the XMLConnector component in this chapter.

XUpdateResolver

The XUpdateResolver component creates XUpdate statements that describe changes made to your XML data within Flash. You use this component with the DataSet component. Well explore this component later in this chapter.

You can download other data components, such as the RemotingConnector and MSSQLXMLConnector, from the Macromedia website.

In addition to the data components, Flash Professional 8 includes data-aware UI components such as the DataGrid, ComboBox, and List. This means that you can use data binding to connect the XML content from the XMLConnector directly to these UI components. You dont have to write ActionScript that loops through collections of childNodes . Instead, you configure the bindings visually through the Component Inspector and Flash does the hard work.

If you prefer to write ActionScript, you can also script the data components. You can use ActionScript to set all of the properties that are available through the Component Inspector. This may be useful if youre adding components to the Stage dynamically. However, scripting data binding between components can be a tricky proposition. Youll probably find it much easier to work with the Component Inspector.

There are some disadvantages to using the data components. First, you can only use these components in Flash Player 7 and above. The second disadvantage is the size of the components. Adding data components dramatically increases the size of your .fla files. Luckily, this size reduces again when you compile your .swf file.

In this chapter, Ill show you how to use the XMLConnector to load XML data into Flash. Well bind the data to UI components and track changes through a DataSet component. Well also look at the process of sending changes to an external data source with the XUpdateResolver component. Ill finish by showing you how to write ActionScript for the XMLConnector class. Well create a simple address book application that lets you display and update XML content in Flash. Note that Flash cant update external data, so youd still need to use a server-side file to update the external XML document.



Foundation XML for Flash
Foundation XML for Flash
ISBN: 1590595432
EAN: 2147483647
Year: 2003
Pages: 93
Authors: Sas Jacobs

Similar book on Amazon

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