2

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?

3 Answers 3

2

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" .../>
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.