ArrayCollection动态添加元素,遍历
???
function initYearList():void{?
?? //动态添加本年度前十年
??? var yearList:ArrayCollection = new ArrayCollection();
?? ?var dt:Date=new Date();
????var curYear:Number=dt.fullYear;
????var firstItem:Object=new Object();
????firstItem.name=curYear as String;
????firstItem.value=curYear as String;
????for (var i:int=0; i < 11; i++)
????{
?????var item:Object=new Object();
?????var tempYear:Number=curYear - i;
?????var tempYearStr:String=tempYear.toString();
?????item["name"]=tempYearStr;
?????item["value"]=tempYearStr;
?????yearList.addItem(item);
????}
}
?
//如果下拉框某个值跟指定值相等,则选中该下拉框项
for each (var item:Object in yearList)
????{
?????if (item["value"] == yearStr)
?????{
??????year.selectedItem=item;
?????}
????}