valter
valter

Reputation: 428

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.

Upvotes: 1

Views: 3756

Answers (2)

Pritesh Ranjan
Pritesh Ranjan

Reputation: 129

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 

Upvotes: 0

Adam Smith
Adam Smith

Reputation: 1937

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 (e.g. if you named one of your own classes ComboBox, rename it).

Upvotes: 2

Related Questions