views:

4667

answers:

4

I believe the simplest way to request data from a server in XML format is to have a PHP/JSP/ASP.net page which actually generates XML based on HTTP GET params, and to somehow call/load this page from Flex.

How exactly can this be achieved using the Flex library classes?

+1  A: 

Never mind, found it: http://livedocs.adobe.com/flex/3/langref/flash/net/URLLoader.html

MidnightGun
+1  A: 

I know you've already found it, but here is some sample code:

public var dataRequest:URLRequest;
public var dataLoader:URLLoader;
public var allowCache:Boolean;

dataLoader = new URLLoader();
dataLoader.addEventListener(Event.COMPLETE, onComplete);
dataLoader.addEventListener(ProgressEvent.PROGRESS, onProgress);
dataLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
dataLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
dataLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);

dataRequest = new URLRequest();
dataRequest.url = "xmlfilelocation.xml" + ((this.allowCache) ? "" : "?cachekiller=" + new Date().valueOf());

dataLoader.load(dataRequest);

public function onComplete(event:Event):void{
    trace("onComplete");
}
public function onProgress(event:ProgressEvent):void{
    trace("onProgress");
}
public function onIOError(event:IOErrorEvent):void{
    trace("onIOError");
}
public function onSecurityError(event:SecurityErrorEvent):void{
    trace("onSecurityError");
}
public function onHTTPStatus(event:HTTPStatusEvent):void{
    trace("onHTTPStatus");
}

I like to add the "allowCache" because Flash/Flex is terrible about caching stuff like this when you don't want it to.

81bronco
+2  A: 

I'd like to add that you can also use mx:HTTPService. If you specify the returnFormat attribute, you would get an XML document as opposed to simple text:

<mx:HTTPService resultFormat="e4x" ..../> or <mx:HTTPService resultFormat="xml" .../>
Laura
A: 

I love you guys. you find answers!

Assembler