Some info on using the ComboBox. Hope this proves useful.
If you've used the ComboBox before, you may have encountered a problem. When you run your movie, your ComboBox may display a label value, but the corresponding data value isn't assigned (ie The specified Change Handler doesn't execute at run time), or conversely, your change handler
does execute on run time, but you don't want it to.
This depends on whether your change handler uses a normal function (function myFunc(){//code}) or a function literal (myFunc = function(){//code})
Function literals are best used if you don't want the Change Handler to execute when the movie is run. For example:
ActionScript Code:
main = new Array();
main.push({label:"John", data:"Dancer" });
main.push({label:"Jack", data:"Artist" });
main.push({label:"Julie", data:"Friend" });
main.sortOn("label");
main.unshift({label:"Select one", data:"default" });//set default value
myComboBox.setDataProvider(main);
onSubmit = function(){
if(myComboBox.getValue()!= "default"){
trace(myComboBox.getValue());
}
/*other code that you may want to run (even if "Select one" is
chosen) - but not upon inital loading*/
}
Whilst standard functions are best used if you do want the Change Handler to be run according to the default value of the ComboBox
ActionScript Code:
main = new Array();
main.push({label:"John", data:"Dancer" });
main.push({label:"Jack", data:"Artist" });
main.push({label:"Julie", data:"Friend" });
main.sortOn("label");
myComboBox.setDataProvider(main);
function onSubmit(){
trace(myComboBox.getValue());
}
For more info on using named arrays in this manor check out the excellent
power of arrays III tutorial