How Do You Populate A Spark List Control With An Array?

Hello, all,
Sorry to come accross so frustrated, but how in the name of God do you populate a Spark list control with the data in an array?  You used to be able to do this with the mx:List control, but the guys developing Flex just had to make things more difficult than they need to be!  I am more of a code purist and prefer doing things the way they have been done for decades, but apparently nothing can ever stay simple!
I simply want to populate a list control with an array and this shouldn't be rocket science!  I found out that I must use a "collection" element, so I decided that an arrayCollection would be best.  However, after searching Adobe's documentation about arrayCollections, I am lost in a black hole of data binding, extra lines of code just to add a new element, the need to sort it, etc...!
Here is my code:
var pendingArray:ArrayCollection = new ArrayCollection();
for ( var i:int = 0 ; i < queue.length ; i++ )
     var item:UserQueueItem = queue[i] as UserQueueItem ;
     if ( item.status == UserQueueItem.STATUS_PENDING )
     pendingArray.addItem({label:item.descriptor.displayName,descriptor:item.descriptor});
Here is the relevant MXML:
<s:VGroup>
     <s:List id="knockingList" width="110" height="100"/>              
</s:VGroup>
I'm not getting any errors, but the list is not populating.
I have seen several examples where the arrayCollection is declared and populated in MXML:
        <mx:ArrayCollection id="myAC">
            <!-- Use an fx:Array tag to associate an id with the array. -->
            <fx:Array id="myArray">
                <fx:Object label="MI" data="Lansing"/>
                <fx:Object label="MO" data="Jefferson City"/>
                <fx:Object label="MA" data="Boston"/>
                etc...
           </fx:Array>
        </mx:ArrayCollection>
That may be fine for an example, but I think this is a rare situation.  Most of the time I would image that the arrayCollection would be created and populated on the fly in ActionScript!  How can I do this?
Thanks in advance for any help or advice anyone can give!
Matt

In your post it seemed like you were trying to take care of many considerations at once: optimization, design, architecture.  I would suggest you get something up and running and then worry about everything else.
If I use data binding, then I will probably have to declare the  arrayCollection as a global variable and then I'll have to write 100 or  so extra lines of code to addItem(), removeItem(), sort(), etc...  It  just seems like too much overhead.
I believe you may have some misconceptions about databinding in general.  You won't have to make it a global variable and you certainly won't need an extra 100 lines of code.  If you did this forum would be a very , very quiet place.
I don't want to use data binding because the original array is refreshed  often and there is one function called by an event that re-declares the  arrayCollection each time, populates it with the array, and then sets  it as the list's dataprovider.
That is the beauty of the ArrayCollection, it can handle the updates to its source Array. I don't know if you need to redeclare the ArrayCollection, resetting the source to the new Array allows everyone involved to keep their references so you don't have to worry about any "spooky" stuff going on.

Similar Messages

  • How to handle multiple selection in the Spark List control with checkbox as itemrenderer?

    Hi All,
    I am using checkbox as an ItemRenderer in spark list.
    I have a query.
    how to handle multiple selection in the Spark List control with checkbox as itemrenderer?
    how to retrieve the selected item label?
    Thank you in advance.

    Hi there, I'll tweak your code a little bit to something like this:
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                    layout="vertical">
        <mx:Script>
            <![CDATA[
                 import mx.events.ListEvent;
                 import mx.controls.CheckBox;
               [Bindable]
               private var mySelectedIndexes:ArrayCollection=new ArrayCollection();
                private function onChange(e:ListEvent):void
                   if(CheckBox(e.itemRenderer).selected){
                             mySelectedIndexes.addItem(e.rowIndex);
                   }else{
                                  mySelectedIndexes.removeItemAt(mySelectedIndexes.getItemIndex(e.rowIndex));     
                   chkList.selectedIndices=mySelectedIndexes.toArray();
            ]]>
        </mx:Script>
    <mx:ArrayCollection id="collection">
            <mx:Object label="Test A"/>
            <mx:Object label="Test B"/>
            <mx:Object label="Test C"/>
            <mx:Object label="Test D"/>
            <mx:Object label="Test E"/>
            <mx:Object label="Test F"/>
            <mx:Object label="Test G"/>
        </mx:ArrayCollection>
    <mx:List id="chkList" dataProvider="{collection}" itemRenderer="mx.controls.CheckBox"  itemClick="onChange(event);" allowMultipleSelection="true"/>
    </mx:Application>

  • How do you print the reminder list

    How do you print the reminder list?

    With Reminders open and your list you'd like to print select, press command "A". After that copy them (command "C"). After that, open your Text Edit app. Once that is open, paste your copy in there (command "V"). From here you can print like you normally do.

  • Custom dragIndicator on Spark List Control

    I have a Spark List Control that is displaying a tilelayout of dynamically imported Images.  Basically, a bunch of thumbnail Images that are displayed in a tile layout.  I have drag drop enabled so that I can reorder these thumbnails and everything is working great except for one thing, the dragIndicator.  In my itemrenderer, I have the Image included in the "dragging" state, but the image is not showing in the dragIndicator.  I am basically just getting a semi-transparent square as my dragIndicator, but I want to be able to actually drag my thumbnail.  Any ideas how to do this?
    Here is my List:
    <s:List id="ImageList1" x="77" y="95" width="858" height="412" dataProvider="{imageAC}"
         itemRenderer="renderers.ImageACSmallItemRenderer" contentBackgroundColor="0x000000"
         borderVisible="false" dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"
         allowMultipleSelection="true" skinClass="skins.General.ListSkin" focusAlpha="0" mouseMove="getImageProxy(event)">
         <s:layout>
              <s:TileLayout columnWidth="76" rowHeight="76" horizontalAlign="center" verticalAlign="middle"
                     horizontalGap="8" verticalGap="8"/>
         </s:layout>
    </s:List>
    Here is my Itemrenderer:
    <fx:Script>
         <![CDATA[
              import mx.utils.ObjectProxy;
              [Bindable]
              public var dataProxy:ObjectProxy;
              private function init():void {
                   dataProxy = new ObjectProxy(data);
         ]]>
    </fx:Script>
         <s:states>
              <s:State name="normal" />
              <s:State name="hovered" />
              <s:State name="selected" />
              <s:State name="dragging" />
         </s:states>
         <mx:Image source="{dataProxy.pathSmall}" horizontalCenter="0" verticalCenter="0" includeIn="normal, hovered, selected, dragging"/>
    </s:ItemRenderer>
    Thanks for any insight!

    Hi Evtim,
    Earlier this summer, you helped me to create an itemRenderer that would allow me to drag photos in a list with a grid layout so that I could re-order them, and the dragIndicator would remain the photo instead of a empty box.  We accomplished this by using the contentCache feature with the Spark BitmapImage.  Now when I drag my photos, they remain photos even while being dragged.  Your very elegant solution ended up looking like this:
    <?xml version="1.0" encoding="utf-8"?>
    <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                            xmlns:s="library://ns.adobe.com/flex/spark"
                                            xmlns:mx="library://ns.adobe.com/flex/mx"
                                            width="76" height="76" focusEnabled="false">
              <fx:Script>
                        <![CDATA[
                                  import spark.core.ContentCache;
                                  static private const contentCache:ContentCache = new ContentCache();
                        ]]>
              </fx:Script>
              <s:states>
                        <s:State name="normal" />
                        <s:State name="hovered" />
                        <s:State name="selected" />
                        <s:State name="dragging" />
              </s:states>
              <s:BitmapImage source="{data.pathSmall}" width="70" height="70" contentLoader="{contentCache}"
                                                horizontalCenter="0" verticalCenter="0" alpha.dragging="2" includeIn="normal, hovered, selected, dragging"/>
    </s:ItemRenderer>
    Now I have another little interesting challenge with this itemRenderer.  I don't want to bore you with details, but the situation is that I will no longer be loading thumbnails that are 70x70 pixels in size, but I will be loading photos with various dimensions that have to be displayed as a 70x70 pixel thumbnail.  So I am going to create a Group that is 70x70 pixels, turn on the clipAndEnableScrolling for the Group, and then place the photos within the Group so that they essentially get cropped.  The images that I import will have to be resized to either 70 pixels wide or 70 pixels high depending on what is the larger dimension of the of the image, and then placed inside the Group so that I get a perfect center-crop of the images.
    So to summarize, I need to load the photos using a loader.  Then I can figure out with the height and width of the photos is.  Then I can scale the photo so that the smaller dimension is 70 pixels, and then I can place it in the Group.  But to do all of this, I can no longer do it in MXML but have to do it in ActionScript... and thus my dilema.  I can't figure out how to use the contentCache properly in ActionScript so that the images stay images when dragged.  Here is what I have so far:
    <?xml version="1.0" encoding="utf-8"?>
    <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                            xmlns:s="library://ns.adobe.com/flex/spark"
                                            xmlns:mx="library://ns.adobe.com/flex/mx"
                                            width="76" height="76" focusEnabled="false" dataChange="init(event)">
              <fx:Script>
                        <![CDATA[
                                  import mx.core.FlexGlobals;
                                  import mx.events.FlexEvent;
                                  import spark.core.ContentCache; 
                                  private var contentCache:ContentCache = new ContentCache();
                                  private var imageLoader:Loader = new Loader();
                                  private var bitmapImg:BitmapImage = new BitmapImage();
                                  private var widthHolder:int;
                                  private var heightHolder:int;
                                  protected function init(event:FlexEvent):void {
                                            var request:URLRequest = new URLRequest(FlexGlobals.topLevelApplication.imageAC[this.itemIndex].pathSmall);
                                            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, createVisuals);
                                            imageLoader.load(request);
                                  private function createVisuals(event:Event):void{
                                            bitmapImg.source = Bitmap(imageLoader.content);
                                            bitmapImg.horizontalCenter = 0;
                                            bitmapImg.verticalCenter = 0;
                                            bitmapImg.smooth = true;
                                            bitmapImg.smoothingQuality = "high";
                                            widthHolder = imageLoader.width;
                                            heightHolder = imageLoader.height;
                                            if (widthHolder > heightHolder) {
                                                      bitmapImg.width = int(Math.round(70*widthHolder/heightHolder));
                                                      bitmapImg.height = 70;
                                            else {
                                                      bitmapImg.width = 70;
                                                      bitmapImg.height = int(Math.round(70*heightHolder/widthHolder));
                                            imageGroup.addElement(bitmapImg);
                        ]]>
              </fx:Script>
              <s:states>
                        <s:State name="normal" />
                        <s:State name="hovered" />
                        <s:State name="selected" />
                        <s:State name="dragging"/>
              </s:states>
              <s:Group id="imageGroup" width="70" height="70" horizontalCenter="0" verticalCenter="0" clipAndEnableScrolling="true"/>
    </s:ItemRenderer>
    So when there is a dataChange in my List, the init() function gets called to load the image.  When the load is complete, the createVisuals() method resizes the image and places it in the Group. Everything is working as expected.  The images get resized, centered and cropped within the group, and smoothed out so that they look nice.  But now when I drag them, I get an empty box while dragging.  I am unsure of how to tie in the contentCache with my bitmapImage object so that it will stay an image while being dragged using actionScript.  I don't know if it is as simple as setting the contentLoader property for the bitmapImage object, or if it is more complicated and I need to set the image source for the "dragging" state.  Could you possibly give me some insight as to how to make this happen in ActionScript?
    Thanks for any insight!
    Bill

  • Spark.List Control: right order in selectedItems

    Hi there,
    How can I get the right order from the selectedItemsArray?
    The docs say:
    "These Vectors contain a list of the selected indices and selected data items in the reverse order in which they were selected. That means the first element in each Vector corresponds to the last item selected."
    But this is not correct. If you have a look in the example "Handling multiple selection in the Spark List control" at the end of
    http://help.adobe.com/en_US/flex/using/WSc2368ca491e3ff923c946c5112135c8ee9e-7fff.html
    you will see, that the order is switching around at every click you make to select an Item in the list.
    Indeed the last selected item is the first item in the array, but the order of the other items is not forseeable...
    My Problem:
    I'm using a list control as an itemeditor in a datagrid. (BTW: Is there a way to use dropshadow on the control?)
    The selectedItems are written to Database as a string in form of "firstselection : secondSelection : thirdSelection".
    I also already tried to push the last selectedItem in an array on every change event and join this to a string at focusOut.
    But that seems to be to late, because the datagridColums editorDataFiled doesn't take the the new values.
    Maybe there are other events , which would be better to use?
    Besides how to handle the prevoiuos selectedItems, which comes already from the db. The best would be, if they are already in the right order at the beginning of that array respectivelythe string. "prevSelectedItem1 : prevSelectedItem2 : newSelectedItem1 ..."
    Another solution would be to have at least the first selectedItem to be the first Item in the string to be written to the db whether is already selected at the editbeginnig or complete new selections are made.
    I hope its understandable, because I'm from Germany
    Every help is welcome!
    Thanks, Kalle!
                <mx:DataGridColumn headerText="Fliesenart" dataField="prd_art" resizable="false" width="300" editorDataField="artLiSelected"  >
                    <mx:itemEditor >
                        <fx:Component>
                            <s:MXDataGridItemRenderer height="22" >
                                <fx:Script><![CDATA[
                                    import mx.collections.ArrayCollection;
                                    import mx.events.FlexEvent;
                                    import spark.events.IndexChangeEvent;
                                    [Bindable]
                                    public var artLiSelected:String;
                                    [Bindable]
                                    public var artTempArr:Array = new Array();
                                    public var artNewTempArr:Array = new Array();
                                    protected function artLi_creationCompleteHandler(artStr:String):void
                                        artLiSelected = artStr;
                                        artTempArr = artStr.split(" : ");
                                        var artTempVec:Vector.<Object> = new Vector.<Object>();
                                        for each (var art:Object in artTempArr) {
                                            artTempVec.push(art);
                                        artLi.selectedItems = artTempVec;
                                    protected function dataCollector():void {
                                        artNewTempArr.push(artLi.selectedItems[0]);
                                        //artLiSelected = artLi.selectedItems.join(" : ");
                                        trace ("change");
                                    protected function dataSubmitter ():void {
                                        artLiSelected = artNewTempArr.join(" : ");
                                        trace ("focusOut");
                                ]]></fx:Script>
                                <s:List id="artLi" height="300" top="5" left="5" right="5"
                                        dataProvider="{outerDocument.artNamesArr}"
                                        change="dataCollector()"
                                        focusOut="dataSubmitter()"
                                        requireSelection="true"
                                         creationComplete="artLi_creationCompleteHandler(data.prd_art)"
                                        allowMultipleSelection="true"
                                        />
                            </s:MXDataGridItemRenderer>
                        </fx:Component>
                    </mx:itemEditor>
                </mx:DataGridColumn>

    Create your own list which must extend from spark.List and then override the function calculateSelectedIndices.
    Then you can do 2 things depending on how you want the order in the selectedItems:
    1. Change all the interval.splice to interval.push (now you have the normal order)
    2. Change the "for (i = 0; i < selectedIndices.length; i++)" to "for (i = selectedIndices.length -1; i > -1; i--)" (then you have a reversed order)

  • How do you backup IPhone contact list to Computer (XP) PC Computer?

    How do you backup IPhone Contact List to PC Computer(XP) ?

    The easiest way that I have found is to open Outlook, go back to Itunes & select your phone.
    Choose the 'Info' tab at the top of the screen & tick the box marked 'Sync contacts with' & choose Outlook from the drop down box.
    Image attached may explain better.
    Regards,

  • How do you populate cfselect when cfgrid selected row is changed

    hi can anyone enlighten me as to how to pass data to a
    cfselect from a cfgrid
    i am using a listner function so that the grid can populate
    form controlswhen a row is selected
    i use bindings on cfinputs so no problem there
    how do u populate a cfselect drop down with data from a grid
    and then how woul i also display query results from another
    query as a second option
    lost
    yes i dont konw much as
    realyy apprecitae your help

    Unfortunately, there's no 'tab-out' event in ABAP standard dynpros - you've got to trigger a PAI event to make that happen (such as hitting 'Enter').

  • How do you clear the reading list in Safari

    How do you clear the reading list in safari ?

    Safari 6 / Mountain Lion
    Section: Remove a page from the Reading List,
    http://support.apple.com/kb/PH11942?viewlocale=en_US
    Best.

  • How do you alphabetise a bulleted list

    How do you alphabetise a bulletted list?

    Donnie Ashworth wrote:
    You have to first convert the list to a table (Format / Table / Convert List to Table)
    Then select a cell in the table, open the table inspector, click on "Table", then go to the Edit Rows & Columns pop-up, and choose Sort Ascending or Descending, whichever you want.
    If you want to then alter the table borders so it doesn't look like a table, you can do that also.
    OR
    You could then convert the Table to Text (Format > Table > Convert Table to Text)
    Regards,
    Barry

  • How do you have multiple apple id's with one itunes

    how do you have multiple apple id's with one itunes

    I have multiple IDs and use the single computer sharing itunes. By 'sharing' I mean we open the pc, open itunes and log in with our individual ID as required.
    While Im logged in I plug in  my device. I transfer my purchases from my device as per the file menu (not the check for auto downloads). I move them as required to whichever playlist I like.
    Then when my son wants to use itunes or update his device, he logs in, plugs in his device, transfers purchases from his device, puts whatever music he wants into his playlist and/or drags direct to the device regardless of who purchased it and then syncs.
    Im not sure how it works associating the pc with only one ID or all that other business- I know I don't fiddle with any of that.

  • How can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    how can you use iMessage between 3 iPads with 3 different users but only one Apple ID?

    No you do not need separate Apple ID's in order to use 3 devices with one Apple ID. I use 4 devices to Message and FaceTime and all use the same Apple ID. You do need to add additional email addresses for the other devices.
    Look at this very informative video for the instructions.
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l

  • How do you copy, for example I work with blue prints and I want to copy a section and copy into another new page?

    How do you copy, for example I work with blue prints and I want to copy a section and copy into another new page?

    Forgot to add that it would be an adjustment layer with some kind of mask on it already. The mask is uncentered when copy and pasted which throws it off.
    I guess the same question would go towards doing the same for an object. How to copy and paste it over to a new doc, keeping its position within the document? is this possible?

  • How do you make a page scroll horizontally with mouse wheel?

    As the title says, how do you make a page scroll horizontally with mouse wheel in edge animate?

    This should get you there
    http://css-tricks.com/snippets/jquery/horz-scroll-with-mouse-wheel/
    1. Load the mousewheel min script via CDN (jquery-mousewheel - cdnjs.com - the missing cdn for javascript and css)  into the Scripts Panel;
    2. Add the provided snippet into your Stage > compositionReady event handler.
    hth
    Darrell

  • How do you overlap PDF's and finish with one PDF file? Need help ASAP

    how do you overlap PDF's and finish with one PDF file?
    Need help ASAP

    I'm not sure if you can do that with CreatePDF.  Try it; you got one free use when you sign up with Acrobat.com
    If not, you will have to use Adobe Acrobat; there is a full-use 30 days trial.

  • How do you get the album pictures displayed with the right songs on my iphone 5

    how do you get the album pictures displayed with the right songs on my i phone 5?

    I have the same problem but i only have iphone 4s its only jsut started in the last 2 weeks or so

Maybe you are looking for