The XMLConnector ComponentThe Professional edition of the new Flash 8 comes with a set of data components. These components are meant to help Flash developers and designers to quickly and efficiently hook their applications into external data sources. The one we are focusing on in this chapter is the XMLConnector component. This component will assist you in connecting to outside XML documents. It has five parameters:
Those are the parameters of the XMLConnector component. The next step is to know how it works. The trigger() MethodThe trigger() method is called on an instance of the XMLConnector component to go out and either send data to an XML document, or receive data from an XML document. It has no parameters. Its generic layout is as follows: myConnector.trigger(); Now what do we do with the data when it comes back? The result EventThe result event is the event we use when the XMLConnector receives data. This event uses a special component event listener. Here is the generic layout of how to use the result event: listener.result=function(result){ trace(result.target.results); } This event has one parameter, the result parameter. The result parameter is the XML being received, and to use it, use result.target.results, which will be the actual XML that has been returned. Enough talking about what it does. Let's do an example:
Some of the preceding code should look familiar. We created a listener for the result event, and then created the event. In the event, we capture the first player node of the XML data coming back to the connector. We walk the tree the same way we would any other XML object, and send the results to the Output panel. Then we add the event listener to the XMLConnector component, and finally trigger the component to go out and get the XML. Run this movie, and you should see a screen similar to Figure 24.7. Notice that the information is sent to the Output panel just as it was before, and the component we dragged out onto the stage is now invisible. Figure 24.7. Using the XMLConnector can have the same results as the XML object with a faster implementation for the developer.There is another component that can make quick work of an XML document, and that is the tree component. |