Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox: Action Script

Status
Not open for further replies.

richiemartin

Technical User
Oct 9, 2003
12
GB
Hello again! As explained before I am new to Flash mx2004 and am struggling to understand the principles behind selecting an item from a component using Action Script.

I have set up a simple Combo Box with three options. My objective is that when one of the options is selected, it takes the user to a new frame. I have tried various different bits of code with various levels of success. On one attempt, I got the combo box to work, but it took me to the same frame, whatever selection I made in the combo box. I have gone round in so many circles that the code I now have does not work. This code (attached) was put together from various books and help menus:

myComboBox.addItem("Image1");
myComboBox.addItem("Image2");
myComboBox.addItem("Image3");
myComboboxListener = new Object ();
comboboxListener.change = function (eventObj){
var eventSource = eventObj.target;
var theSelectedItem = eventSource.selectedItem;
var theSelectedItemLabel = theSelectedItem.label;
gotoAndStop (5);
}
myComboBox.addEventListener("change", comboboxListener);

Please can someone explain to me what I’m doing wrong. Your time and help is much appreciated.
 
Your names are a little off and your vars are only retrieving the combobox name and the label. I imagine you want the data value? Try this:

Code:
myComboBox.addItem("Image1");
myComboBox.addItem("Image2");
myComboBox.addItem("Image3");
comboListener = new Object ();
comboListener.change = function (eventObj){
	//retrieve the "data" value of the selected item
    var theSelectedItem = eventObj.target.value;
	//evaluate the value and redirect (replace "data1" with one of your data values)
	if (theSelectedItem == "data1"){
		_root.gotoAndStop(5);
	}else{
		trace("You didn't select item 1");
	}
	
}
myComboBox.addEventListener("change", comboListener);

Hope it helps!

Wow JT that almost looked like you knew what you were doing!
 
Superb, thats just what i needed! i think im slowly beginning to understand the different bits of code. i have also discovered the loadMovie event, so instead of getting the user to go to different frames, can just load the image straight into a movie-clip. just need to figure out the scaleing issues now!

thanks again, your help is much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top