Macromedia Flash Professional 8 UNLEASHED [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Macromedia Flash Professional 8 UNLEASHED [Electronic resources] - نسخه متنی

David Vogeleer, Eddie Wilson, Lou Barber

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






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:


myConnector.trigger();

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(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:


1.

Create a new Flash document.

2.

Save this document as

xmlConnector.fla in the same directory as the team1.xml file.

3.

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

4.

Now create a new layer and call it

actions .

5.

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 = result.target.results.firstChild.firstChild;
//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.



/ 318