获取动态控件值的方法
新new出来的控件通过 getChildByName得到控件对象
例:
var gridRow:GridRow = new GridRow();
gridRow.width=grid.width;
gridRow.height=grid.height*0.1;
var item1:GridItem = new GridItem();
item1.width=gridRow.width*0.2;
item1.setStyle("backgroundColor","#A5D8F3");
item1.setStyle("horizontalAlign","center");
item1.setStyle("verticalAlign","middle");
item1.setStyle("borderStyle","solid");
var item2:GridItem = new GridItem();
item2.width=gridRow.width*0.3;
item2.setStyle("verticalAlign","middle");
item2.setStyle("borderStyle","solid");
var item3:GridItem = new GridItem();
item3.width=gridRow.width*0.2;
item3.setStyle("backgroundColor","#A5D8F3");
item3.setStyle("horizontalAlign","center");
item3.setStyle("verticalAlign","middle");
item3.setStyle("borderStyle","solid");
var item4:GridItem = new GridItem();
item4.width=gridRow.width*0.3;
item4.setStyle("verticalAlign","middle");
item4.setStyle("borderStyle","solid");
var label:Label=new Label();
label.text="预计收款日期:";
var dateField:DateField=new DateField();
dateField.name="dfplanPaymentDate";
dateField.formatString="YYYY-MM-DD";
dateField.dayNames=["日","一","二","三","四","五","六"];
dateField.monthNames=["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"];
dateField.yearNavigationEnabled=true;
dateField.width=item2.width*0.8;
var label2:Label=new Label();
label2.text="预计收款金额:";
var ntipt:NumberInput=new NumberInput();
ntipt.name="dfplanPaymentMoney";
ntipt.width=item4.width*0.4;
var btn:Button=new Button();
btn.label="保存";
btn.addEventListener(MouseEvent.CLICK,savePayMentDetails);
var btn2:Button=new Button();
btn2.label="删除";
btn2.addEventListener(MouseEvent.CLICK,deleteGridRow);
item1.addChild(label);
item2.addChild(dateField);
item3.addChild(label2);
item4.addChild(ntipt);
item4.addChild(btn);
item4.addChild(btn2);
gridRow.addChild(item1);
gridRow.addChild(item2);
gridRow.addChild(item3);
gridRow.addChild(item4);
grid.addChildAt(gridRow,grid.numChildren-2);
public var gridRow:GridRow;
private function deleteGridRow(event:Event):void{
gridRow=event.target.parent.parent;
Alert.yesLabel="是";
Alert.noLabel="否";
Alert.show("确定要删除该条信息吗?","提示",3,this,delPayMentDetailsAlert);
}
private function delPayMentDetailsAlert(event:CloseEvent):void{
if(event.detail==Alert.YES){
for(var i:int=0,len:int=paymentDetailsAc.length;i<len;i++){
var paymentDetails:PaymentDetails=paymentDetailsAc.getItemAt(i) as PaymentDetails;
if(paymentDetails!=null){
var uid:String=paymentDetails.uid;
if(uid==gridRow.uid){
paymentDetailsAc.removeItemAt(i);
}
}
}
grid.removeChild(gridRow);
}
}
private function savePayMentDetails(event:Event):void{
var df:DateField=event.target.parent.parent.getChildren()[1].getChildByName("dfplanPaymentDate") as DateField;
var planPaymentDate:Date=df.selectedDate;
if(planPaymentDate==null){
Alert.show("请选择预计收款日期!","提示");
return ;
}
var planPaymentMoney:Number=event.target.parent.getChildByName("dfplanPaymentMoney").text;
if(planPaymentMoney<=0){
Alert.show("请填写预计收款金额!","提示");
return;
}
var paymentDetails:PaymentDetails=new PaymentDetails();
paymentDetails.planPaymentDate=planPaymentDate;
paymentDetails.planPaymentMoney=planPaymentMoney;
paymentDetails.uid=event.target.parent.parent.uid;
paymentDetailsAc.addItem(paymentDetails);
Alert.show("保存成功!","提示");
}
for循环里,不要for(var j:int = 0; j < _map[i].length; j++)这样写,
用for each或者for(var j:int=0, nLen:int = _map[i].length; j < nLen; j++);
在flex里,这两种写法差别很大,循环去XML的NODE,5000的数据,后者只要1,2秒,前者要用10几秒,这就是差别
友情链接:珀莱雅 欧诗漫 专卖 http://store.taobao.com/shop/view_shop.htm?mytmenu=mdianpu&utkn=g,2djlrizuga4a1324992712104&user_number_id=372143050