Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

DataService Fill Operation Completion

Avatar

Level 1
How can you determine exactly when a Flex DataService fill
operation has completed?



ex:



dsDataService.fill(arrayList, 'flex:hql', 'From
com.package.Object);

trace(arrayList.length); // <-- This returns 0



***



while(arrayList.length < 1) {} // <--- This never ends





The trace returns 0 but if I wait a second or two before
calling it it returns with the correct size of 30.

The arraylist will also successfully bind to a datagrid.



Can I do something with the AsyncToken that is returned from
the fill to know when the operation is completed?



Thanks for your help!

1 Accepted Solution

Avatar

Correct answer by
Level 4
AsyncToken is one way to go. Here's an example where an
AsyncToken is used. Note that inline functions are being used for
result and fault handing but you can break these to seperate
functions as well.



var fillToken:AsyncToken = dsDataService.fill(arrayList);

fillToken.addResponder(new AsyncResponder(

function (result:Object, token:Object=null):void

{

// Do something with the result

},

function (error:Object, token:Object=null):void

{

// Do something with the error

}));

View solution in original post

0 Replies

Avatar

Correct answer by
Level 4
AsyncToken is one way to go. Here's an example where an
AsyncToken is used. Note that inline functions are being used for
result and fault handing but you can break these to seperate
functions as well.



var fillToken:AsyncToken = dsDataService.fill(arrayList);

fillToken.addResponder(new AsyncResponder(

function (result:Object, token:Object=null):void

{

// Do something with the result

},

function (error:Object, token:Object=null):void

{

// Do something with the error

}));

Avatar

Not applicable
Right, I'd much rather see people start out with normal AS3
functions to

simplify things until they get a handle (pun intended) on the
nature of async

programming.



import mx.rpc.events.FaultEvent;

import mx.rpc.events.ResultEvent;

import mx.rpc.AsyncResponder;





private function doFill():void

{

var token:AsyncToken = dsDataService.fill(arrayList);

var responder:AsyncResponder = new
AsyncResponder(handleResult, handleFault);

token.addResponder(responder);

}



private function handleResult(event:ResultEvent):void

{

trace("Result received. Length = " + arrayList.length);

// Handle result.

}



private function handleFault(event:FaultEvent):void

{

// Handle fault.

}







See
http://livedocs.adobe.com/flex/201/langref/mx/rpc/AsyncResponder.html
too.





Avatar

Level 4
I prefer inline functions for simple one/two liner
result/fault handling and break them into seperate functions when
the handling logic gets more complicated. People have different
styles and I don't think there's one right/easier way.

Avatar

Level 1
Mete & Peter,



Thanks for the quick response; just what I was looking for.



Andrew R