简体   繁体   中英

AS3 selecting a Combo Box inside a Movie Clip

I am not sure if there is a better way to do this, and if there is please let me know. But right now, I have a list of combo boxes with names in them.

The combo boxes are stu1, stu2, stu3, ect all the way to 63 and held in the allStudents MovieClip

for(var i = 0; i < allStudents.length; i++)
{
    var newTempStudent:ComboBox = allStudents.getChildAt(i);

    newTempStudent.dataProvider.addItem({label: fullName, data:fullName});
    newTempStudent.getChildAt(i).dataProvider.sortOn("label");
    newTempStudent.getChildAt(i).selectedItem = allStudents.getChildAt(i).getItemAt(i);

}

essentially i am trying to:

get all 63 combo boxes to update from the same dataProvider,

sort them alphabetically,

then set the default selected to each student (stu1 should display dataProvider(0), stu2 should display dataProvider(1) as it's default selection)

The error I am getting is:

Scene 1, Layer 'Layer 1', Frame 1, Line 83 1118: Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type fl.controls:ComboBox.

Now I am assuming I am getting that becasue it is looking is the movie clip which is the display object and executing combobox commands, but I'm not sure how to do this per se.

Originally I was going to do this with a dataGrid, but it became too complicated when I was trying to link the dataGrid to checkBoxes for attendance.

Any and all help is greatly appreciated!

Try this code :

for(var i = 0; i < allStudents.length; i++)
{
    var newTempStudent:ComboBox = allStudents.getChildAt(i) as ComboBox;

    newTempStudent.dataProvider.addItem({label: fullName, data:fullName});
    newTempStudent.getChildAt(i).dataProvider.sortOn("label");
    newTempStudent.getChildAt(i).selectedItem = allStudents.getChildAt(i).getItemAt(i) as ComboBox;

}

getChildAt() returns a DisplayObject, so you need to cast it as a ComboBox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM