Flex4 动态添加删除组件

private function creatCombox(IdName:String):void{
				
	var comSeleCriteriaTemp:ComboBox=new ComboBox;
	bcSelectionCriteria.addElement(comSeleCriteriaTemp);
	comSeleCriteriaTemp.id="comSeleCriteria"+IdName;
	comSeleCriteriaTemp.name="comSeleCriteria"+IdName;
	comSeleCriteriaTemp.styleName="dropDownList1";
	comSeleCriteriaTemp.dataProvider=comSeleCriteria.dataProvider;
	comSeleCriteriaTemp.width=comSeleCriteria.width;
	comSeleCriteriaTemp.height=comSeleCriteria.height;
	comSeleCriteriaTemp.selectedIndex=0;
	comSeleCriteriaTemp.x=comSeleCriteria.x;
	comSeleCriteriaTemp.y=55+30*tempAddDelete;
	
	var comConditionTemp:ComboBox=new ComboBox;
	bcSelectionCriteria.addElement(comConditionTemp);
	comConditionTemp.id="comCondition"+IdName;
	comConditionTemp.name="comCondition"+IdName;
	comConditionTemp.styleName="dropDownList1";
	comConditionTemp.dataProvider=comCondition.dataProvider;
	comConditionTemp.width=comCondition.width;
	comConditionTemp.height=comCondition.height;
	comConditionTemp.selectedIndex=0;
	comConditionTemp.x=comCondition.x;
	comConditionTemp.y=55+30*tempAddDelete;
	
	var txtValueTemp:TextInput=new TextInput();
	bcSelectionCriteria.addElement(txtValueTemp);
	txtValueTemp.id="txtValue"+IdName;
	txtValueTemp.name="txtValue"+IdName;
	txtValueTemp.width=txtValue.width;
	txtValueTemp.height=txtValue.height;
	txtValueTemp.x=txtValue.x;
	txtValueTemp.y=55+30*tempAddDelete;
	
	var btnGetValueTemp:Button =new Button;
	bcSelectionCriteria.addElement(btnGetValueTemp);
	btnGetValueTemp.label="GET VALUE";
	btnGetValueTemp.id="btnGetValue"+IdName;
	btnGetValueTemp.name="btnGetValue"+IdName;
	btnGetValueTemp.width=btnGetValue.width;
	btnGetValueTemp.height=btnGetValue.height;
	btnGetValueTemp.styleName="button1";		
	btnGetValueTemp.x=btnGetValue.x;
	btnGetValueTemp.y=55+30*tempAddDelete;
	
	var btnAddTemp:Button =new Button;
	bcSelectionCriteria.addElement(btnAddTemp);
	btnAddTemp.label="ADD";
	btnAddTemp.id="btnAdd"+IdName;
	btnAddTemp.name="btnAdd"+IdName;
	btnAddTemp.width=btnAdd.width;
	btnAddTemp.height=btnAdd.height;
	btnAddTemp.styleName="button1";		
	btnAddTemp.x=btnAdd.x;
	btnAddTemp.y=55+30*tempAddDelete;
	btnAddTemp.addEventListener(MouseEvent.CLICK,btnAdd_clickHandler)
		
	var btnDeleteTemp:Button =new Button;
	bcSelectionCriteria.addElement(btnDeleteTemp);
	btnDeleteTemp.label="DELETE";
	btnDeleteTemp.id="btnDelete"+IdName;
	btnDeleteTemp.name="btnDelete"+IdName;
	btnDeleteTemp.width=btnDelete.width;
	btnDeleteTemp.height=btnDelete.height;
	btnDeleteTemp.styleName="button1";		
	btnDeleteTemp.x=btnDelete.x;
	btnDeleteTemp.y=55+30*tempAddDelete;
	btnDeleteTemp.addEventListener(MouseEvent.CLICK,btnDelete_clickHandler)

}


protected function btnDelete_clickHandler(event:MouseEvent):void
{
	// TODO Auto-generated method stub

	var tempDel:IVisualElement= event.currentTarget as IVisualElement;
	var tempY:int=tempDel.y;
	var tempCount:int=bcSelectionCriteria.numElements;
	var tempIndex:int=bcSelectionCriteria.getElementIndex(tempDel);

	bcSelectionCriteria.removeElement(bcSelectionCriteria.getElementAt(tempIndex));
	bcSelectionCriteria.removeElement(bcSelectionCriteria.getElementAt(tempIndex-1));
	bcSelectionCriteria.removeElement(bcSelectionCriteria.getElementAt(tempIndex-2));
	bcSelectionCriteria.removeElement(bcSelectionCriteria.getElementAt(tempIndex-3));
	bcSelectionCriteria.removeElement(bcSelectionCriteria.getElementAt(tempIndex-4));
	bcSelectionCriteria.removeElement(bcSelectionCriteria.getElementAt(tempIndex-5));
	
	tempCount=bcSelectionCriteria.numElements;

	for(var i:int=0;i<tempCount;i++)
	{
		if(bcSelectionCriteria.getElementAt(i).y>tempY)
		{
			bcSelectionCriteria.getElementAt(i).y-=30;
		}
	
	}
	
}


添加和删除功能


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值