dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Move items from one list to another using a button

  1. #1
    Junior Member
    Join Date
    Jul 2006
    Posts
    21

    Move items from one list to another using a button

    I'm trying to figure out how to (with the use of a button) move items from one list component to another. I basically want to duplicate what happens when you drag and drop one item in a list to another.

    Thanks in advance!

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Well, it's not going to be handled the same as if you are using the dragEnabled/dropEnabled properties of components that support it (since it's automated) so the answer to your question boils down to your choice of how to handle it and like most goals there are multiple ways to end up there. That said....my example here is by no way the standard...just one possible solution

    PHP Code:
    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
    <![CDATA[
    import mx.collections.*;
    import mx.controls.Alert;
           
     [Bindable]
     private var selectedItem:Object;
                
     [Bindable]        
       private var AC1:ArrayCollection = new ArrayCollection([
      {label: 'AAAAA', data: 'AAAAA'},
       {label: 'BBBBB', data: 'BBBBB'},
      {label: 'CCCCC', data: 'CCCCC'}  
      ]);
      
      [Bindable]
         private var AC2:ArrayCollection = new ArrayCollection([
      {label: 'DDDDD', data: 'DDDDD'},
       {label: 'EEEEE', data: 'EEEEE'},
      {label: 'FFFFF', data: 'FFFFF'}
      
      ]);
      
      
     private function moveItem():void

    {
     var sort:Sort = new Sort();
     sort.fields = [new SortField("label", true)];
       
    if(l1.selectedIndex != -1)
      {
          
     AC2.addItem(AC1[l1.selectedIndex])
     AC1.removeItemAt(l1.selectedIndex);  
     AC1.sort = sort;
     AC1.refresh();
     AC2.sort = sort;
     AC2.refresh();
      }
    else
      {
     Alert.show("Select An Item From List #1 First!!");
      }
      }

      
           ]]>
        </mx:Script>

    <mx:List id="l1" width="188" color="blue"
               dataProvider="{AC1}"
                x="32" y="70"/>

    <mx:List id="l2" width="188" color="blue"
               dataProvider="{AC2}"
                x="268" y="70" enabled="true"/>

    <mx:Button id="b1" width="188" label="Move Selection To List #2"
             click="moveItem()" x="32" y="234"/>
    <mx:Label x="91" y="39" text="List #1" fontWeight="bold" fontSize="14"/>
    <mx:Label x="334" y="39" text="List #2" fontWeight="bold" fontSize="14"/>

    </mx:Application>

  3. #3
    Junior Member
    Join Date
    Jul 2006
    Posts
    21
    Thanks Chris! I got it working...lovley!

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center