我从'for'循环动态创建ComboBox时遇到了一些问题。我在尝试使用子字符串拉出实例ID时发现了这一点,然后执行e.target.name单击事件以发现子项被命名为“instance9,instance48,instance87”等等。下面是我用来创建这些框的循环和函数。
for (var i:int = 0; i<pictURL.length; i++)
{
var myBox:Sprite = new Sprite();
var pictURLReq:URLRequest = new URLRequest(pictURL[i]);
var pictLdr:Loader = new Loader();
fMyBox();
fPlaceBoxes();
fItemName();
fComboBox();//calls the function to create the combobox
fItemQty();
fAddBtn();
}
function fComboBox():void
{
var iOpsBox:ComboBox = new ComboBox();
iOpsBox.x = this.getChildByName("itemName" + i + "_txt").x + 10;
iOpsBox.y = this.getChildByName("itemName" + i + "_txt").y + 25;
iOpsBox.width = 75;
if (this["item" + i + "Ops"].length != 0) //checks an array to see if any items to be populated into the combobox exists
{
iOpsBox.dataProvider = new DataProvider(this["item" + i + "Ops"]);
}
else
{
iOpsBox.visible = false;
}
iOpsBox.name = "opsBox" + i;
addChild(iOpsBox);
//iOpsBox.addEventListener(Event.CHANGE, fChangeHandler);
}
我确信这可能是某种简单的修复,我只是没有看到,但任何帮助都会非常感激!