Thanks. In this case the status values are the newArrayHashMap 
keys.  I am populating a comboBox with the results from the 
function.  The comboBox is then used to filter an arrayCollection 
that has the same underlying array that is used in the function -
 "array".  "status", is a member of the value objects (accountVO) 
that are contained in "array".  The task was to dynamically load the 
comboBox with the unique "status" values that exist in the database.
For instance the accounts database might contain the following 
fields:

   accountId : String;
   accountName : String;
   status : String;


The possible status values might be "Open", "Closed" and "On Hold".  
The user is presented with a data grid view of the results from an 
accounts search.  At this time, the user may wish to filter the 
results to 
only show the "Closed" accounts.  Sure, the values in the comboBox 
could be hard coded.  But the program would have to be maintained 
when a new "status" value is added to the database.  Also, the 
comboBox should only show "status" values that exist in the search 
results.  If the search results included "Active" and "Inactive" 
accounts, the comboBox should only present those same values.  If it 
was hard coded, the user would be able to select the "On Hold" 
comboBox option, which in this case would present a blank dataGrid.  
Don't want to confuse the user this way.

The "All" option is used programmatically to un-filter the 
arrayCollection.  "All" is the default value for the comboBox - in 
this case only because it is alphabetically first in the function's 
status array.  Gordon, I think that your method of shifting 
the "All" value after the array has been sorted is better - just in 
case a new status value (like "Active") is added to the database.  I 
suppose that the function could be improved even further by changing 
the name of the field ("status") to a function parameter, so that 
the function may be re-used.  If you're interested, I'll post a 
version.

By now, I'm sure that I've acheived total confusion.  If not, I hope 
this helps someone.

Tim Hoff


--- In [email protected], "Gordon Smith" <[EMAIL PROTECTED]> 
wrote:
>
> That's a nice improvement on my suggestion because it doesn't 
require a
> second loop. But since you only care about the key, not the value, 
that
> you put into newArrayHashMap, I wouldn't burden the memory manager 
and
> the garbage collector by constructing a new Object() for each 
value;
> using a scalar value like 1 or true would be more efficient. But 
this
> will only matter if the status array will be large.
> 
> Also, if "All" gets sorted alphabetically along with the other 
status
> codes, will users know it's special?
> 
> - Gordon
> 
> 
> -----Original Message-----
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On
> Behalf Of turbo_vb
> Sent: Wednesday, April 12, 2006 2:21 PM
> To: [email protected]
> Subject: [flexcoders] Re: AS3 Array Question
> 
> Doug and Gordon, thanks for the advise.  I decided on the 
following 
> solution.
> 
> public function populateStatusArray(array:Array):void 
> {
>     var newArrayHashMap : Object = new Object();              
>     var status : Array = new Array;
>     status.push("All");
>               
>     var n:int = array.length;
>     for (var i:int = 0; i < n; i++) 
>     {
>         if (newArrayHashMap[array[i].status] == undefined)
>         {
>             newArrayHashMap[array[i].status] = new Object();
>             status.push(array[i].status);
>          } 
>     }           
>     status.sort();
>     ModelLocator.getInstance().statusArray = status;        
> }
> 
> Tim Hoff
> 
> 
> --- In [email protected], "Gordon Smith" <gosmith@> 
> wrote:
> >
> > You can use a plain Object as a Set... see the code below.
> > 
> > You first put key/value pairs into the Object, but it makes no
> > difference what the values are. You just care about the keys, 
and 
> the
> > Object's hash table takes care of ensuring that setting a key 
more 
> than
> > once is harmless.
> > 
> > Then you iterate over the Object, pulling out the unique keys 
into 
> an
> > Array that can be sorted.
> > 
> > Finally, you stick "All" at the top, after the sort.
> > 
> > - Gordon
> > 
> > 
> > <?xml version="1.0" encoding="utf-8"?>
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
> width="600"
> > height="600">
> > 
> >     <mx:Script>
> >     <![CDATA[
> > 
> >             [Bindable]
> >             private var array:Array = 
> [ "B", "C", "A", "B", "A", "D"
> > ];
> >             
> >             public function getUniqueItems(array:Array):Array
> >             {
> >                     var uniqueItemHash:Object = {};
> >                     var n:int = array.length;
> >                     for (var i:int = 0; i < n; i++)
> >                     {
> >                             uniqueItemHash[array[i]] = true;
> >             }
> >                     
> >                     var uniqueItemArray:Array = [];
> >                     for (var p:String in uniqueItemHash)
> >                     {
> >                             uniqueItemArray.push(p);
> >                     }
> > 
> >                     uniqueItemArray.sort();
> >                     uniqueItemArray.unshift("All");
> >                     return uniqueItemArray;
> >             }
> > 
> >     ]]>
> >     </mx:Script>
> > 
> >     <mx:ComboBox dataProvider="{getUniqueItems(array)}"/>
> > 
> > </mx:Application>
> > 
> > -----Original Message-----
> > From: [email protected] 
> [mailto:[EMAIL PROTECTED] On
> > Behalf Of Doug Lowder
> > Sent: Tuesday, April 11, 2006 5:00 PM
> > To: [email protected]
> > Subject: [flexcoders] Re: AS3 Array Question
> > 
> > For large arrays, it will be more efficient to do this:
> > 
> > 1) Make a copy of the input array, if necessary
> > 2) Sort the array by status
> > 3) Iterate through the array once, storing new status values and 
> > skipping the duplicates
> > 
> > 
> > --- In [email protected], "turbo_vb" <TimHoff@> wrote:
> > >
> > > I'm trying to populate a dataProvider array for a comboBox 
that 
> > > contains unique status values from another array, that is used 
> as 
> > > the dataProvider for a dataGrid.  The comboBox is used to 
filter 
> > the 
> > > dataGrid.  The code below works, but I seem to remember seeing 
> > this 
> > > done somewhere that doesn't use nested for statements.  Does 
> > anyone 
> > > know how I can identify if the array's status value already 
> exists 
> > > in the new status array without iterating the new array every 
> time?
> > > 
> > >       public function populateStatusArray(array:Array):void {
> > >           
> > >       var status : Array = new Array;
> > >       status.push("All");
> > >           
> > >             var n:int = citations.length;
> > >             for (var i:int = 0; i < n; i++) {
> > >                   var m:int = status.length;
> > >                   var found:Boolean = false;
> > >                   for (var j:int = 0; j < m; j++) {
> > >                           if (status[j] == array[i].status){
> > >                                   found = true;
> > >                           }
> > >                   }
> > >                   if (found == false) {
> > >                           status.push(array[i].status);
> > >                   }
> > >             }           
> > >             status.sort();
> > >             ModelLocator.getInstance().statusArray = 
> > status;        
> > >         }
> > > 
> > > Thank You,
> > > Tim Hoff
> > >
> > 
> > 
> > 
> > 
> > 
> > 
> > --
> > 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

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> 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/
 


Reply via email to