Coerce array of objects into selectedItems Array

Posted on 2009-02-20
Last Modified: 2012-06-21
I have a list in my mxml, and when I query the database I pull back an array of objects that should be hi lighted in the list. The trace in the function below prints one of the properties from the object fine, but it errors out on the next line.

When I trace on report.rsStat[x] as Array, it says null. How can I get each one of those objects into the selectedItems as an Array?

Or is there a better way to put all the objects in that array into the selectedItems so the proper items in the list are hi lighted?
if(report.rsStat.length > 0){

	var rssCursor:IViewCursor = this.rssCollection.createCursor();

	for (var x:String in report.rsStat)




			trace("VAR " + x + " " + report.rsStat[x].name);

			this.rsStat.selectedItems = report.rsStat[x] as Array; //ERROR here

			this.rsStat.dispatchEvent(new ListEvent(ListEvent.CHANGE));




Open in new window

Question by:hallikpapa
    LVL 19

    Accepted Solution

    report.rsStat is an array correct?  Its an array of objects.  So report.rsStat[x].name is one of the items you want selected?  You can cast a single item to an array.

    Try this.
                            trace("VAR " + x + " " + report.rsStat[x].name);
                            var temp:Array = new Array();
                            temp[0] = report.rsStat[x];                    
                            this.rsStat.selectedItems = temp;
                            this.rsStat.dispatchEvent(new ListEvent(ListEvent.CHANGE));

    Open in new window


    Author Comment

    Well, that got rid of my error, but it isn't highlighting the items in the list that is now contained in rsStat.selectedItems.

    What am I doing wrong?
    <mx:Binding source="rsStat.selectedItems" destination="selectedRSStat" />
    <mx:FormItem direction="horizontal" label="Location(s):" required="true" enabled="{editMode}">
    	<mx:List id="rsStat" 
    		enabled="{ > -1}"
    		toolTip="Hold CTRL key to select multiple Location"

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now