您的位置:首页 > 其它

Flex4 动态添加删除组件

2011-08-24 10:15 615 查看
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;
}

}

}


添加和删除功能
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: