For the moment I have only two tasks on three. This of the second
project (out of three) isn't here.
here is the code :
private function getTasks():void
{
currentState='';
if (document.listProject.selectedIndex == -1)
{
tasksArray = new ArrayCollection();
var projectsArray:ArrayCollection =
ArrayCollection(document.listProject.dataProvider);
var tmpArray:ArrayCollection = new ArrayCollection();
var i:int;
for (i = 0; i < projectsArray.length; i++)
{
tmpArray.addEventListener(CollectionEvent.COLLECTION_CHANGE,
collectionChangeHandler);
taskDataService.fill(tmpArray, "tasksProject",
[projectsArray.getItemAt(i).id]);
}
}
else
taskDataService.fill(document.tasksArray, "tasksProject",
[document.listProject.selectedItem.id]);
}
private function collectionChangeHandler(event:CollectionEvent):void
{
if (event.kind == CollectionEventKind.RESET)
{
// display the length using the event.target.length
var tmpArray:ArrayCollection = ArrayCollection(event.target);
var j:int;
for (j = 0; j < tmpArray.length; j++)
document.tasksArray.addItem(tmpArray.getItemAt(j));
}
}
--- In [email protected], "jason_williams_mm" <[EMAIL PROTECTED]>
wrote:
>
> Each fill operation is asynchronous and so are the calls to Alert.show
> (). This means that code doesn't stop when these lines of code are
> executed it continues to run the very next line.
>
> With the fill operation you will not get a valid length until the
> server responds to the request, however, during that time you will
> continue to execute more fill requests until all projects within the
> projectsArray have been iterated.
>
> It is not clear what you are after here, if you want to display the
> length of the filled collection after the server has responded then
> you could do something like the following:
>
> tmpArray.addEventListener(CollectionEvent.COLLECTION_CHANGE,
> collectionChangeHandler);
> taskDataService.fill(...);
>
> function collectionChangeHandler(event:CollectionEvent):void
> {
> if (event.kind == CollectionEventKind.RESET)
> {
> // display the length using the event.target.length
> }
> }
>
> The RESET kind is only dispatched when the collection has been
> initially filled when managed by DataService.
>
> There are more sophisticated approaches to this problem as well like
> using a responder with the AsyncToken returned from the fill()
> method, but, it is unclear if you are only after debugging
> information or not. If you really only want debugg information then
> use the <mx:TraceTarget /> in your application MXML and a debug
> player then inspect the flashlog.txt or the console when using
> FlexBuilder in debug mode.
>
> --- In [email protected], "jonathan_merey" <mereyj@>
> wrote:
> >
> > My problem is simple. I know each of my projects have tasks. If I
> > delete the loop. The second Alert.show print the good length. But
> with
> > the loop, the second Alert.show print 0 except for the last loop.
> If i
> > delete the first Alert.show, the second print 0 even for the last
> > loop. I understood its due to a problem of exectution time but how
> > can i do to do what i want. Thank you.
> >
> >
> > Here is the code :
> >
> > private function getTasks():void
> > {
> > currentState='';
> > if (document.listProject.selectedIndex == -1)
> > {
> > var projectsArray:ArrayCollection =
> > ArrayCollection(document.listProject.dataProvider);
> > var tmpArray:ArrayCollection = new ArrayCollection();
> > var i:int;
> > for (i = 0; i < projectsArray.length; i++)
> > {
> > mx.controls.Alert.show(projectsArray.getItemAt(i).id);
> > taskDataService.fill(tmpArray, "tasksProject",
> > [projectsArray.getItemAt(i).id]);
> > mx.controls.Alert.show(tmpArray.length.toString());
> >
> > }
> > }
> > else
> > taskDataService.fill(document.tasksArray, "tasksProject",
> > [document.listProject.selectedItem.id]);
> > }
> >
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/