One of the nice ways to handle these situations in Flex is to use data binding. Since the system listens for and handles events automatically, you can do something like this in MXML:
currentState="{theUser.length > 1 && theUser.getItemAt(0).administratorGroupKey == 1 ? 'AdminOption' : ''}" This is a bit awkward because of the > and & chars in the data binding expression. It is easier when you are dealing with the return value of the "getItem" method since that has a simple "result" property you can bind to, or when you are binding to the array collection as a whole since you can bind to theUser property directly. If data binding is not appropriate, the other change I'd recommend is that rather than adding the processAdminOption as a listener for the "result" event on the ID_USERS data service, I'd set processAdminOption as a responder on the AsyncToken returned by the fill. It is a stylistic change but I find it easier to manage responders to specific fill operations rather than use the event which is fired for any operation performed on that data service. It avoids the if/else logic in your event handler to figure out which operation this is. Jeff ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ripe101 Sent: Thursday, January 25, 2007 3:05 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: DataService fill not filling on first try? timing issue? Continuing in the tradition of replying to my own posts when I find the solution... I found the issue is caused by the fill method being processed asynchronously to the actionscript execution (duh!) I didn't know that obviously ;) I just moved my code that processes the returned object into an event handler that gets called when a result is returned by the fill... So one question, is there a way to avoid "filling" the first array collection and just dealing with the object that is returned in the ResultEvent? it looks like this (it's ugly): private function getAdminOption(username:String):void { var theUser:ArrayCollection = new ArrayCollection; ID_USERS.addEventListener("result", processAdminOption); ID_USERS.fill(theUser,"IdUser.single",[username]); } private function processAdminOption(event: ResultEvent):void { if (event.result.length != 0) { if (event.result[0].administratorGroupKey == 1) { currentState='AdminOption'; } else { currentState=''; } } else { currentState=''; } } cheers, JK --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "ripe101" <[EMAIL PROTECTED]> wrote: > > I have a fill method being called in an event handler, and I can see > the correct data coming back in FDS (from Hibernate), but my > ArrayCollection is empty the first time the method is called. > > If I trigger the exact same event with the same parameter a second > time it behaves as expected. I think I am missing something subtle... > > the event handler is as follows: > > private function getAdminOption(username:String):void > { > var theUser:ArrayCollection = new ArrayCollection; > ID_USERS.fill(theUser,"IdUser.single",[username]); > if (theUser.length != 0) > { > if (theUser.getItemAt(0).administratorGroupKey == 1) > { > currentState='AdminOption'; > } > else > { > currentState=''; > } > } > } > > Anyone else seen this happen? > > Thanks > JK >