Select value of a DropDownList via actionscript in Flex 4?

There are a couple ways to do this - if you need to do it using the label or the value, you can loop though the arraycollection like this.

There are a couple ways to do this - if you need to do it using the label or the value, you can loop though the arraycollection like this: protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void { var searchTerm:String = "EST"; var result:* = null; for each(var zone:* in timeZonesArray) { if(searchTerm == zone. DdlData) { result = zone; break; } } ddlTimezones. SelectedItem = result; } However, if you keep a reference to the time zones individually or you're getting them from some other part of the app, you can do it more cleanly: import mx.collections.

ArrayCollection; import mx.events. FlexEvent; var EST:Object = {ddlLabel:"Eastern Time", ddlData:"EST"}; var CST:Object = {ddlLabel:"Central Time", ddlData:"CST"}; var MST:Object = {ddlLabel:"Mountain Time", ddlData:"MST"}; var PST:Object = {ddlLabel:"Pacific Time", ddlData:"PST"}; Bindable protected var timezonesArray:ArrayCollection = new ArrayCollection( EST, CST, MST, PST ); protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void { ddlTimezones. SelectedItem = EST; } This way, you don't have to worry about interrogating every object in the list, because you're staying at the level of whole objects rather than reaching into them.It also makes it easier if you want to replace your list of JSON style objects with a class definition, if you start needing to store more complicated information about time zones.

I like that second solution. +1. :) – Jason Towne Mar 8 at 16:57 Yep, thanks a lot, turning every part of the ArrayCollection into separate objects is simply brilliant.It expands the possibilities in many ways.

THANKS AGAIN! :-) – Jivago Mar 8 at 18:02 @Jivago, Don't forget to mark this as the answer. :) – Jason Towne Mar 8 at 19:29 @Jason Towne, Thank you for the reminder.

I'm new to this forum. Really like the way it works :-) – Jivago Mar 8 at 17:39.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions