简体   繁体   中英

How to set a combobox value dynamically using AS3?

How can I set a combobox value using as3?

It needs to work like this!

I have these values on the combobox:

20 30 40 50


These are font size numbers.

I just need sothing like this:

combobox.selectedIndex=AutoSelect(combobox,"40");


I found this function:

private function findItemIndex (element:ComboBox, dataString:String):int {
    var index:int = 0;
    for (var i = 0; i < element.length; i++) {
        if (element.getItemAt(i).data.toString() == dataString) {
            index = i;
            break;
        }
        else {
        }
    }
    return index;
}

myComboBox.selectedIndex = this.findItemIndex(myComboBox, "stringToMatch");

But I'm getting this error:

1000: Ambiguous reference to ComboBox.

Your error is unrelated to what you're trying to do in the function. The error is telling you that there is more than one ComboBox class in your class path, and it doesn't know which one you're referring to. This can be cleared up by fully qualifying the class name, or by removing the ambiguity (eg if you named one of your own classes ComboBox, rename it).

This error pops up when, the compiler is not sure which component you want to use. Two components may have the same name. To resolve the ambiguity use the component name with its complete path. The case with ComboBox is that both Spark and mx library have it. To resolve this error, include the fully qualified name where the compiler gives an error.

Try this for spark's comboBox

private function findItemIndex (element:spark.components.ComboBox, dataString:String):int 

Try this for mx's comboBox

private function findItemIndex (element:mx.controls.ComboBox, dataString:String):int 

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