PDA

View Full Version : Can't Access Combobox From Method


omnivore
01-19-2006, 05:26 PM
I'm have trouble accessing a combobox from a class method.
The combobox should be set to index 3. Instead it shows blank.
I can click, see the selections, click on a selection. But it remains blank.
Text boxes work fine. Just the comboboxes won't work.

dynamic class AgendaItem extends MovieClip {
function AgendaItem() {
}
function attachForm(tilepath){
form = _root.attachMovie("form", "form", 20000);
populateForm();
}
function populateForm(){
form.combo_place.selectedIndex = 3;
}
}

The form movieclip has a combobox named combo_place
Any solutions?
Thanks,
Pete

Paerez
01-19-2006, 06:59 PM
You should probably keep the form as a class property to maintain scope:
dynamic class AgendaItem extends MovieClip {
var form:MovieClip;
function AgendaItem() {
}
function attachForm(tilepath){
this.form = _root.attachMovie("form", "form", 20000);
populateForm();
}
function populateForm(){
form.combo_place.selectedIndex = 3;
}
}

since they are in seperate functions the "form" variable will not persist beyond the attachForm function call.

omnivore
01-19-2006, 07:13 PM
since they are in seperate functions the "form" variable will not persist beyond the attachForm function call.
Thanks Paerez, but that didn't do it.
I will keep the form as a class property though.

FWIW - The text boxes work fine but not the comboboxes.
Any other suggestions?

I appreciate your help!
--
Pete

omnivore
01-19-2006, 07:28 PM
Found a work around:

I pass the numeric value of the index in the method:
this.form.combo_place_num = 1;

and set the combobox in the form movieclip:
combo_place.selectedIndex = combo_place_num;

Let me know if there's a better way.
At least it works now
--
Pete

Paerez
01-19-2006, 07:36 PM
ah yes. That is because the combo box is not loaded when you run the populate form method. By doing it in the mc, you set the value and when the CB loads, it sets the index.

The alternative, which is more complicated but safer in general is using a MovieClipLoader along with the onLoadInit event to set parameters in to the movie.