Expand my Community achievements bar.

A question about DataService and data binding

Avatar

Former Community Member
With the help of Adobe Flex DataService sample, I set up a
project that can get data from my Oracle db successfully, here are
some codes:

......

public var ds:DataService;

[Bindable]

public var road:ArrayCollection;

public function initApp():void{

road = new ArrayCollection();

ds = new DataService("speed");

ds.fill(road);

}

......

<mx:DataGrid id="dg" dataProvider="{road}"
editable="true" x="40" y="647">

<mx:columns>

<mx:DataGridColumn dataField="id" headerText="ID"
editable="false"/>

<mx:DataGridColumn dataField="speed"
headerText="Speed"/>

<mx:DataGridColumn dataField="sample" headerText="Sample
Size"/>

<mx:DataGridColumn dataField="x" headerText="X axis"/>

<mx:DataGridColumn dataField="y" headerText="Y axis"/>

</mx:columns>

</mx:DataGrid>

......

I noticed that after the swf page has been requested, an
empty DataGrid control was drawn first, then some data fill into
the grids about 1~2 secs later. Here is the promble:I want to draw
a line using the data from db, but either on Application's
CreateComplete event or applicationComplete event, I can't use the
'road' because it is EMPTY! It means that after the application
complete( that's to say all components has been created), data from
db hasn't arrived, and it will arrive about 1~2 secs later. Who can
tell me how can I control this procedure, I mean how can I get data
just after the method fill() is called?

Thanks a lot!
2 Replies

Avatar

Level 3
The fill() method is an asynchronous call for data across the
network so there's bound to be some amount of latency. When you
invoke fill() it returns an AsyncToken that you can add a responder
to. A responder defines result and fault callbacks, and the result
callback of your responder will be triggered when the data arrives
at the client. In your responder's result callback you could
access/use/draw the 'road' which will now have its data.



The Application's creationComplete event is dispatched long
before network calls are guaranteed to have finished so don't base
your data handling on that.



Best,

Seth

Avatar

Former Community Member
Thank you very much! With your advice, I've drawn my paths
successfully.