The XMLConnector Component

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?

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:

 listener.result=function(result){     trace(; } 

This event has one parameter, the result parameter. The result parameter is the XML being received, and to use it, use, which will be the actual XML that has been returned.

Enough talking about what it does. Let's do an example:


Create a new Flash document.


Save this document as xmlConnector.fla in the same directory as the team1.xml file.


Drag an instance of the XMLConnector component onto the stage, give it an instance name of xmlCon, and use these settings for the parameters:

  • URL team1.xml

  • direction receive

  • ignoreWhite true

  • multipleSimultaneousAllowed false

  • suppressInvalidCalls false


Now create a new layer and call it actions.


In the actions layer, open the Actions panel, and place these actions in it:

 //create the listener object var xmlListen:Object=new Object(); //create the event xmlListen.result=function(result){     var playerNode =;     //this will search through the players       while(playerNode){         //the first property node         var propNode = playerNode.firstChild;          //this will search through the players' nodes          while(propNode){             var nodeName:String = propNode.nodeName;             var nodeValue:String = propNode.firstChild.nodeValue;             trace(nodeName+"="+nodeValue);           propNode = propNode.nextSibling;          }       playerNode = playerNode.nextSibling;       } } //add the event listener xmlCon.addEventListener("result", xmlListen); //trigger the XML Connector to get the XML xmlCon.trigger(); 

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.

Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319 © 2008-2017.
If you may any questions please contact us: