PDA

View Full Version : ComboBox - useful info


Mortimer Jazz
06-05-2003, 09:22 AM
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:

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

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 (http://www.flashmagazine.com/html/618.htm) tutorial

farafiro
06-05-2003, 01:17 PM
;)

ScratUAD
07-08-2003, 09:00 PM
this may make me sound like an idiot... but I've been trying to qonquer that combo box for months now... and your scripting did it! Thank you so very much for taking that brief moment to post it!

Thank you!

Mortimer Jazz
07-08-2003, 11:34 PM
:)

freddycodes
07-09-2003, 12:35 AM
Of course one could also achieve this effect by dynamically assigning the changeHandler after the data is loaded.

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);
myComboBox.setChangeHandler("onSubmit");
function onSubmit(){
trace(myComboBox.getValue());
}