I have a flex 4 app consuming some services using the code generation tool in Flash Builder.
One of the services returns a fairly large result (500kb ish) If I use firebug I can see the download finishing after a couple of seconds. But then the flex app hangs for a number of seconds once the result has been received.
I presume this is a delay in casting the result to the generated type.
This delay is horribly ugly in my app as it can happen while video is playing, causing the video to stall but the audio to continue playing.
Is there any way to either speed up this delay or allow it to run as normal user code does allowing other visual operations to continue?
If there isn't I'll have to write a manual factory to put the result into the required value object without casting.
Have you tried adding an event listener that gets called when you get the result back from the web service to see if that helps? Something like:
protected function myComponent_creationCompleteHandler(event:FlexEvent):void
{
getWebServiceResult.token = webService.webServiceMethod();
getWebServiceResult.addEventListener(ResultEvent.RESULT, functionForResult);
}
protected function functionForResult(event:ResultEvent):void
{
//do something with the results returned by your web service
}
where myComponent (in this example) is the ID of the visual component where the results are being displayed. Note: I pulled this from one of my remote object calls to a ColdFusion function so the syntax might not be exactly what it needs to be for a web service call.
Also, I don't know if you can use paging for something like this, like you can with a database call, but that might also be something to look into. I've not used it myself, though, so I can't help you much there.
Good luck!
~ Amanda
The code snipped you provided is exactly how I am consuming them already.
If I set break points at the
getWebServiceResult.token = webService.webServiceMethod();
and the
Result event handler
The first break will be hit, if i continue then the data will be loaded from the server, then the whole app will hang for a number of seconds once the data has been received.
Only then will the result handler be fired.
I am getting my object out from the result event. Eg...
protected function functionForResult(event:ResultEvent):void
{
var myObj:SomeValueObject = SomeValueObject(event.data);
}
The constructor for SomeValueObject isn't doing anything special. No for loops as far as I know. It is just the class created by the FlexBuilder service wizard.
The delay occurrs even if i am running the web services locally.
Still haven't found a solution for this one.
I tried moving back to using manually written Services.mxml instead of the generated AS code and it still didn't help.
public function getMediaObject(id:Number,includeDimensionData:Boolean):void
{
var token:AsyncToken = svc.GetGraph(id,includeDimensionData);
var responder:mx.rpc.Responder = new mx.rpc.Responder(getMediaObject_onResult, getMediaObject_onFault);
token.addResponder(responder);
}
protected function getMediaObject_onResult(event:ResultEvent):void
{
}
In the above code once the service has been called it will go off and load the response (800kb XML web service response) then once it returns, before hitting the responder onResult function the whole app locks for a number of seconds.
If anyone has any idea of what may cause this I would be VERY appreciative!
The XML contains both small data fields and larger fields containing base64 encoded images. Could it be a performance limitation of flash's xml parser?
Thanks in advance!
Ben
The performance profiler will tell you what is taking all the time, but I
would suspect both XML parsing and base64 decoding. The entire 800Kb XML
response is decoded before the result handler fires. That's a lot of nodes
and bytes to visit.
One solution is to just get the XML and parse it yourself, either using
pseudo-threads or lazy decoding.
Another is to use multiple requests that will generate smaller responses.
Another is to use RemoteObject.
Yet another is to use LCDS and paging.
North America
Europe, Middle East and Africa
Asia Pacific