PDA

View Full Version : ComboBox: how to extract the values?


jansensan
12-22-2004, 04:08 PM
Hiyall! I have this combobox that I'd like the user to use (hm... bad phrasing...) to choose something. Once the item is selected, I want my MC that includes the combobox to be removed and depending on the choice of the user, a MC will be attached to the _root.

I have tried to read and understand many tutorials about comboboxes, but I guess I'm not quick or there was nothing about what I was looking for. here is my code so far, and I'll attach the .fla.

Anyone may tell me what to do?

onClipEvent (load) {
this.question_txt.text = "Please select a shape:";
}
onClipEvent (enterFrame) {
onSelect = function () {
var userChoice = this.selector_cb.getValue ();
trace (userChoice);
if (userChoice == null) {
this.question_txt.text = "Nothing is selected. Please select a shape:";
} else {
_root.attachMovie (userChoice, "shape_mc");
_root.selector_mc.removeMovieClip ();
}
};
}

palacajoe
12-22-2004, 04:58 PM
First: Never use onClipEvent. If you saw onClipEvent in some tutorial, it was a very outdated one.

Second: You are using a Flash MX component; so if you're using Flash 2004, set your publish settings to Flash 6 and ActionScript 1.

Here's the code that will work:

selector_mc.question_txt.text = "Please select a shape:";
selector_mc.selector_cb.setChangeHandler("selectorChange", this);
function selectorChange(c) {
var userChoice = c.getSelectedItem().data;
if (userChoice != null) {
_root.attachMovie(userchoice, "shape_mc", 1);
_root.selector_mc.removeMovieClip ();
}
};

On the selector_cb in the components panel delete the "onSelect" changehandler. Just leave the field blank. Now you're rockin'!

palacajoe
12-22-2004, 05:01 PM
By the way, put that code on the first frame of your movie. To make your code more readable, you could define your _cb values on the first frame too, rather than in the components panel. That way you won't have to dig into your movie to find or change code.

jansensan
12-22-2004, 06:18 PM
thanx so much, i needed to work a bit around what you did to make it like I wanted, but you put me on the right path! thanx a bunch!