The XMLConnector component is an alternative to the XML class. Instead of writing ActionScript to work with XML data, you can use the XMLConnector. The component can send, receive, and both send and receive XML content in the same way as the load , send , and sendAndLoad methods of the XML class. The most common use for the XMLConnector is to load an external XML document and bind the data to UI components .
One drawback of the XML class is that there is no support for XML schemas. You cant validate an XML document or view the required structures for your elements in Flash. This isnt the case with the XMLConnector. You can import sample XML data so that Flash displays a representation of the structure. Once youve done this, you can find the names of all elements and attributes as well as their datatypes in the Component Inspector panel.
The XMLConnector component allows you to bind data directly to UI components such as the TextInput, ComboBox, List, or DataGrid. Instead of writing ActionScript, you can configure the Component Inspector so that Flash automatically adds information from the external XML document to the UI components. You can add formatting to control how the content displays in your movie.
Binding directly to UI components means that a user cannot update the data. If you want users to update the data, you can track updates to the XML content by including a DataSet component and an XUpdateResolver. This is a more complicated process. Ill explain both processes in the next sections.
If you are using Flash to display data from an external XML document, the process is simple. You load the XML document into Flash using an XMLConnector component. You then bind the XML content directly to one or more user interface components. You can also bind the data through the DataHolder or DataSet component, although this is less common. Figure 8-1 shows the process for displaying this type of data.
Things become more complicated if you need Flash to track the changes made by the UI components. Flash can monitor these changes, but because it cant modify external content, youll have to rely on server-side pages to update the external data source.
Youll still use the XMLConnector to load the XML document. However, youll need to bind the XML data to a DataSet component first before binding the DataSet to your UI components. The DataSet monitors changes made to the data by the UI components. The DataSet can then generate a list of all changes for the XUpdateResolver component. The XUpdateResolver converts the changes into statements for processing by a server-side file. Figure 8-2 shows this process.
Whichever process you use, youll need to start by adding an XMLConnector and configuring it with the Component Inspector. You should note that all of the security restrictions on external data still apply to the XMLConnector component. You can find out more about these restrictions in Chapter 4.