Use HTTPService. The "send()" method returns an AsyncToken, a dynammic
object to which you can add any property name=value you want. In your
case, set token.filename = source[i]. then in the result handler, you
can access this value and use it as the key in an associative array.
The code snippets below show one usage of the AsyncToken.
Tracy
Sample code using HTTPService, e4x, handler function to populate a list
item.
Also shows usage of AsyncToken.
The DataGrid tag:
<mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>
The HTTPService tag:
<mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)"
fault="..../>
Script block declaration:
import mx.rpc.Events.ResultEvent;
[Bindable]private var _xlcMyListData:XMLListCollection;
Invoke send:
var oRequest:Object = new Object();
oRequest.Arg1 = "value1";
var callToken:AsyncToken = service.send(oRequest);
token.callId = "myQuery1";
Result Handler function:
private function onResult(oEvent:ResultEvent):void {
var xmlResult:XML = XML(event.result); //converts
result Object to XML. can also use "as" operator
var xlMyListData:XMLList = xmlResult.myListData; //depends on xml
format, is row data
_xlcMyListData = new XMLListCollection(xlMyListData); //wrap the
XMLList in a collection
trace(_xlcMyListData.toXMLString()); //so you can see
exactly how to specify dataField or build labelFunction
var callToken:AsyncToken = oEvent.token;
var sCallId = callToken.callId; //"myQuery1"
switch(sCallId) {
case "myQuery1":
doQuery2();
break;
...
}
}//onResult
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Thursday, October 25, 2007 9:57 AM
To: [email protected]
Subject: [flexcoders] Problem with loading multiple external xml files
I have an array named 'source' which consists of external xml file
names whose content i am trying to load into another array called
'content'. I tried with following:
----------------
for (i=0; i<source.length; i++){
XML_URL = "http://localhost/temp/" + source[i];
myXMLURL = new URLRequest (XML_URL);
myLoader = new URLLoader (myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
}
function xmlLoaded(evt:Event):void{
content.push(myLoader.data);
}
---------------
The problem is that this way i only get content of the last xml file
from 'source' array and other 'content' elements are 'undefined'. Does
anyone know solution to this problem or maybe have another way of
doing this?
thanks in advance
--
Best regards,
Mirko mailto:msabljic[at]gmail.com