flex 动态创建复选框

发布时间:2019-07-22 09:20:51

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" x="46" y="42" creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.controls.CheckBox;

private function initApp():void
{
  var items:Array = ["apple","boy","cat","dog","eye","fox"];

  for(var i:int=0;i<items.length;i++)
  {
    var checkBox:CheckBox = new CheckBox();
    checkBox.id = "checkBox" + i.toString();
    checkBox.label = items[i].toString();
    checkBox.setStyle("fontSize",14);
    checkBox.x = 100;
    checkBox.y = (i + 1) * 25;
    checkBox.addEventListener(Event.CHANGE,checkBox_change);
    this.addChild(checkBox);//也可是this.gridItem.addChild(checkBox)
  }    
}

private function checkBox_change(e:Event):void
{
  if(e.target.selected)
  {
    lbItems.text = lbItems.text+e.target.label+" ";
  }
  else
  {
    lbItems.text = lbItems.text.replace(e.target.label,"");
  }
}
]]>
</mx:Script>
<mx:Label id="lbItems" x="56" y="245" text="Your choice is: " width="345" fontSize="14"/>
</mx:WindowedApplication>




Card image cap
APP STORE
Card image cap
应用宝
Card image cap
小米
Card image cap
华为