Flex实例一(实现左右多选框的拖拽、点击选择,双击选择,左右互选)

效果图:



 

代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="450" height="350" creationComplete="initApp()" backgroundColor="#FFFFFF" fontSize="12">
<mx:Script>
  <![CDATA[
   import mx.events.ScrollEvent;
     import mx.rpc.events.FaultEvent;  
     import mx.rpc.events.ResultEvent;
     import mx.controls.Alert;
     import mx.collections.ArrayCollection; 
     private function initApp():void{
      left.dataProvider=['广东','广西','内蒙古','北京','上海','江苏','江西','湖南','湖北','四川','西藏','新疆'];
      right.dataProvider=[];
    }
    private function toRight():void
    {
     var selectItems:Array = left.selectedItems;
     var selectIndexs:Array = left.selectedIndices;
        Alert.show(selectItems.toString()+"---"+left.selectedIndices.toString());
        if(right.dataProvider == null) 
        { 
             right.dataProvider = new ArrayCollection(); 
        } 
        for( var i:Number = 0 ; i < selectItems.length ; i++ )
        {
              ArrayCollection(right.dataProvider).addItem(selectItems[i].toString()); 
              ArrayCollection(left.dataProvider).removeItemAt(selectIndexs[i]);
        }
        
      
    }
    private function toLeft():void
    {
     var selectItems:Array = right.selectedItems;
     var selectIndexs:Array = right.selectedIndices;
        //Alert.show(selectItems.toString()+"---"+left.selectedIndices.toString());
        if(left.dataProvider == null) 
        { 
             left.dataProvider = new ArrayCollection(); 
        } 
        for( var i:Number = 0 ; i < selectItems.length ; i++ )
        {
              ArrayCollection(left.dataProvider).addItem(selectItems[i].toString()); 
              ArrayCollection(right.dataProvider).removeItemAt(selectIndexs[i]);
        }
    }
 
  ]]>
</mx:Script>
  <mx:Panel x="0" y="0" width="450" height="350" layout="absolute" title="左右互选">
    <mx:Label x="7" y="3" text="当前内容"/>
    <mx:List x="7" y="25" id="left" width="168" height="275" allowMultipleSelection="true"
          dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" doubleClickEnabled="true" itemDoubleClick="toRight()">
    </mx:List>
    <mx:Label x="243" y="3" text="移动内容"/>
    <mx:List x="243" y="25" id="right" width="180" height="272" allowMultipleSelection="true"
          dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" doubleClickEnabled="true" itemDoubleClick="toLeft()">
    </mx:List>
    <mx:Button x="183" y="121" label="-&gt;&gt;" click="toRight()" id="bt_r"/>
    <mx:Button x="183" y="178" label="&lt;&lt;-" click="toLeft()" id="bt_l"/>
  </mx:Panel>
</mx:Application>

 



 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值