2 Replies Latest reply on Dec 14, 2010 5:53 AM by flexillu10

    Simple Question regarding copying the s:List Selected Items

    flexillu10 Level 1

      How can i add an item from List A to another List/Array B once it is selected in List A.

       

      List A is populated by a HTTPService last result image url. But i want the whole item copied to a new List/Array.

       

      I would love example code

        • 1. Re: Simple Question regarding copying the s:List Selected Items
          chandu3107 Level 2

          Hope this is what you are looking

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
              <fx:Declarations>
                  <!-- Place non-visual elements (e.g., services, value objects) here -->
              </fx:Declarations>
              <fx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                      import mx.controls.Alert;
                      import mx.events.FlexEvent;
                      private var object:Object;
                      private var _dataProvider:ArrayCollection = new ArrayCollection();
                      [Bindable]private var _secdataProvider:ArrayCollection = new ArrayCollection();

           

                      protected function application1_creationCompleteHandler(event:FlexEvent):void
                      {
                          for(var i:int=0; i<10; i++)
                          {
                              object = new Object;
                              object.Name = i;
                              _dataProvider.addItem(object);
                          }
                          list1.dataProvider = _dataProvider;
                      }

           


                      protected function list1_clickHandler(event:MouseEvent):void
                      {
                          if(event.currentTarget.selectedItem!=null && _secdataProvider.getItemIndex(event.currentTarget.selectedItem)==-1 )
                          {
                              _secdataProvider.addItem(event.currentTarget.selectedItem);
                          }
                      }

           

                  ]]>
              </fx:Script>
              <s:List id="list1" x="166" y="90" labelField="Name" click="list1_clickHandler(event);"></s:List>
              <s:List id="list2" x="362" y="90" labelField="Name" dataProvider="{_secdataProvider}"></s:List>
          </s:Application>

          • 2. Re: Simple Question regarding copying the s:List Selected Items
            flexillu10 Level 1

            Ok i think that worked, but how can i stop an item being added more than once to the list?

             

            E.g if i click an item 4 times it gets added 4 times