The XMLConnector Component
The 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:
- URL
The path either relative or absolute to the XML document. - direction
This parameter is for either sending or receiving XML information or both. - ignoreWhite
This parameter is similar to the ignoreWhite property of the XML object; it will set whether or not Flash should take into account the white space of the XML document when parsing. - multipleSimultaneousAllowed
This parameter sets whether the connector can make several calls to the XML document at once. - suppressInvalidCalls
If TRue, this parameter will halt the TRigger() method being called if data bound parameters are invalid.
Those are the parameters of the XMLConnector component. The next step is to know how it works.
The trigger() Method
The 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:
Now what do we do with the data when it comes back?
myConnector.trigger();
The result Event
The 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:
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:
listener.result=function(result){
trace(result.target.results);
}
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.
