The whole chain of what?
Storing the dataProvider, the loop limit,
and the data you're looking for in local vars WOULD be more efficient because
they remain the same throughout the loop and it is inefficient to evaluate them
over and over. But the item changes with each iteration so storing it in a
local var before accessing its data property is just an extra step.
var dp:Object
= cboCountry.dataProvider;
var n:int = dp.length;
var country:String = event.result.COUNTRY;
for (var i:int = 0; i < n ; i++)
{
if (dp.getItemAt(i).data == country)
{
cboCountry.selectedIndex = i;
break;
}
}
- Gordon
From:
[email protected] [mailto:[EMAIL PROTECTED] On Behalf Of jeremy lu
Sent: Tuesday, May 16, 2006 3:00
AM
To: [email protected]
Subject: Re: [flexcoders] FB2B3
programmatically select an item in a ComboBox
hi Gordon,
that's interesting, please bring it back here if you do get time to check it,
thanks :-)
btw, my rationale behind this is: player don't have to evaluate the whole chain
during the loop by assigning it to a variable, but I might just be wrong.
On 5/16/06, Gordon
Smith <[EMAIL PROTECTED]>
wrote:
I'd expect that introducing an unnecessary local var would
make it slightly less efficient, but I haven't looked at the bytecode for the
two cases.
- Gordon
glad that helped.
adding var itm:* = cboCountry.dataProvider.getItemAt(i) might be a little
bit efficient.
On
5/16/06, Steve Gustafson <[EMAIL PROTECTED]>
wrote:
That
solved it!
The key is using the dataProvider.length instead of the ComboBox .length
I shortened the code block a little to:
for(var i:Number = 0; i < cboCountry.dataProvider.length ; i++)
{
if (cboCountry.dataProvider.getItemAt(i).data == event.result.COUNTRY)
{
cboCountry.selectedIndex = i;
break;
}
}
Thanks for the help!
On
5/15/06, jeremy lu <[EMAIL PROTECTED]>
wrote:
well, I believe all the getItemAt() methods are removed from List-base
components like Combobox, List, DataGrid in F2B3.
to do the loop correctly, try this:
for(var i:Number = 0; i < cboCountry.dataProvider.length; i++)
{
var itm:* = cboCountry.dataProvider.getItemAt(i);
if( itm.data == event.result.COUNTRY )
{
cboCountry.selectedIndex = i;
break;
}
}
On
5/16/06, Simeon Bateman <[EMAIL PROTECTED] >
wrote:
Well I
dont know exactly what is wrong, but using flex builder it would be pretty easy
to set a break point on the "if" line of code and then step through
the loop to ensure that those to variables are what you think they should be.
I use a mac and so my solution is to just use an alert to pop up the 2 items
each loop so I can compare them.
Give it a look, you might find that the two don't actually match up.
The other thing, is that if you are doing this on a tabnavigator or accordian
and the page you are setting has not yet been drawn then the items wont get
selected even if they match. If this is the case you might have to look
into the creationPolicy for the parent, to ensure the children are all created
before you try to set properties on them.
Hope that helps.
--
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
--
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
--
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
--
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
|