Groups | Blog | Home
all groups > flash actionscript > june 2006 >

flash actionscript : comboBox with dataProvider


yarkehsiow
6/19/2006 11:09:47 PM
hello,
i have a comboBox which is filled with info provided by dataProvider, eg:

ccbOne.dataProvider=["Penny","Nickel", "Dime"];

the problem is that "Penny" , when clicked does not produce the desired
effect... it only works after clicking one of the other items on the list.
is there a strategy for getting around this? should i just put one more item
in the array saying "choose a coin" and then not include it in the if statement?

thanks.





ccbOne.dataProvider=["Penny","Nickel", "Dime"];


var oListener:Object = new Object();
oListener.change = function(oEvent:Object):Void {
var myNewValue= oEvent.target.value;
if (myNewValue == "Penny") {
ccbTwo.dataProvider= myVar1;
}
};
ccbOne.addEventListener("change", oListener);
landogilator
7/3/2007 12:00:00 AM
There are a variety of ways to handle this change that might result in more
consistent operation In your change function, try using the
ccbOne.selectedIndex to determine if a value has been selected. For instance:

if(ccbOne.selectedIndex == 0)

I would also recommend using attributes in your array assignment, so instead
of ["Penny", "Nickel", "Dime"], you have [label:"Penny", label:"Nickel",
label:"Dime"] or [{data:1,
label:"Penny"},{data:5,label:"Nickel"},{data:10,label:"Dime"}]

Then you can reference the combo by ccbOne.data[selectedIndex].
So if you want to detect a Nickel: if(ccbOne.data[selectedIndex] == 5)


However, your code may be as simple as needing oEvent.target.value.text

Could have some syntax errors in the above, but hopefully you get the idea.

regards

ps...Try a trace within the change function and see what string myNewValue
takes on each time you click.
AddThis Social Bookmark Button