2 Replies Latest reply on Sep 15, 2009 11:49 PM by Shongrunden

    Move XML item from one spark list to another?

    Handycam Level 1

      I have an application with 2 spark lists:

       

       

           <s:List id="cardList" dataProvider="{recipeListCollection}" left="10" bottom="20" height="520" width="520" skinClass="skins.CardListSkin" change="listChangeHandler(event)">
                <s:layout>
                     <s:TileLayout verticalGap="15" horizontalGap="10" orientation="columns" requestedRowCount="3" />
                </s:layout>
                <s:itemRenderer>
                     <fx:Component>
                          <comp:RecipeCard/>
                     </fx:Component>
                </s:itemRenderer>
           </s:List>
           
           <s:Panel id="menuSheet" right="10" bottom="10" width="300" height="500">
                <s:List id="sidesList" dataProvider="{sides}" horizontalCenter="0">
                     <s:itemRenderer>
                          <fx:Component>
                               <s:ItemRenderer>
                               <s:states>
                               <s:State name="normal" />
                               <s:State name="hovered" />
                               <s:State name="selected" />
                               </s:states>
                               <s:Label text="{data.title}" color.hovered="red" />
                               </s:ItemRenderer>
                          </fx:Component>
                     </s:itemRenderer>
                </s:List>
           </s:Panel>
      

       

      I need to add a button that, when an item in the first list (cardList) is selected, that item is "copied" to the "sidesList".

       

      How would I do this?

        • 1. Re: Move XML item from one spark list to another?
          Shongrunden Adobe Employee

          The attached sample code will hopefully get you started.

          • 2. Re: Move XML item from one spark list to another?
            Shongrunden Adobe Employee

            Hmm, the attachment was eaten up, hopefully this will come through:

             

            <s:Application
                xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark">
               
                <fx:Declarations>
                    <s:ArrayList id="sourceArrayList">
                        <fx:String>item 0</fx:String>
                        <fx:String>item 1</fx:String>
                        <fx:String>item 2</fx:String>
                        <fx:String>item 3</fx:String>
                        <fx:String>item 4</fx:String>
                        <fx:String>item 5</fx:String>
                    </s:ArrayList>
                   
                    <s:ArrayList id="destinationArrayList" />
                </fx:Declarations>   

                <s:layout>
                    <s:VerticalLayout />
                </s:layout>

                <s:List id="list1" dataProvider="{sourceArrayList}" change="destinationArrayList.addItem(list1.selectedItem)">
                      <s:layout>
                           <s:TileLayout />
                      </s:layout>
                      <s:itemRenderer>
                           <fx:Component>
                                   <s:ItemRenderer>
                                       <s:states>
                                           <s:State name="normal" />
                                           <s:State name="hovered" />
                                           <s:State name="selected" />
                                       </s:states>
                                    <s:Button label="{data}" color.selected="red" />
                                   </s:ItemRenderer>
                           </fx:Component>
                      </s:itemRenderer>
                 </s:List>
                
                <s:List id="list2" dataProvider="{destinationArrayList}">
                    <s:itemRenderer>
                        <fx:Component>
                            <s:ItemRenderer>
                                <s:states>
                                    <s:State name="normal" />
                                    <s:State name="hovered" />
                                    <s:State name="selected" />
                                </s:states>
                                <s:Label text="{data}" color.hovered="red" color.selected="blue" />
                            </s:ItemRenderer>
                        </fx:Component>
                    </s:itemRenderer>
                </s:List>
                
            </s:Application>