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!

MX 2004 Menu Bar Component 1

Status
Not open for further replies.

richiemartin

Technical User
Oct 9, 2003
12
GB
Hi, I am extremely new to Flash and need some assistance with creating a menu bar with drop down menus. I am using Flash MX2004 pro and so using the MenuBar component from the ‘Components’ window. I have dragged the menu bar onto the page and added the following code:

menu = myMenuBar.addMenu("Modules");
menu.addMenuItem({label:"Buffering", instanceName:"BufferingInstance"});
menu.addMenuItem({label:"Spatial Analysis", instanceName:"SAInstance"});
menu.addMenuItem({label:"Interpolation", instanceName:"InterpolationInstance"});
menu = myMenuBar.addMenu("Questionnaire");
menu = myMenuBar.addMenu("Chatroom");

However, I have now tried numerous bits of code to activate the buttons when selected but to no avail. For example, when the ‘Questionnaire’ button is selected, I would like to go to another flash movie.

Any help would be much appreciated
rich
 
You have to add an event listener to handle the change. Try this:

Code:
menu = myMenu.addMenu("modules");
menu.addMenuItem({label:"Buffering", instanceName:"BufferingInstance"});
menu.addMenuItem({type:"separator"});
menu.addMenuItem({label:"Spatial Analysis", instanceName:"SAInstance"});

myListener = new Object();
myListener.change = function(evt){
	var item = evt.menuItem;
	trace(item.attributes.instanceName);
}

menu.addEventListener("change",myListener);

Hope it helps!

Wow JT that almost looked like you knew what you were doing!
 
hi, thank you very much for the help. i have added the code and think i understand what its there for. But i am still confused with how i can attach code to the text in the menu. not sure if this makes sense!

for example. if you have a normal button, you add the code:
on (release) {
getURL ("etc etc.html");
}

but with this component there are no buttons, i just added the code in the actions panel to create the menu.

So not sure how i can get the text/buttons to be selected in the menu and go to a new page.

sorry if this doesnt make much sense!
your help is much appreciated
 
By adding the listener you are accepting an "event" broadcast from the menubar component. By evaluating the "instanceName" attribute of the menu item in the listener you can take appropriate action.

Example:

Code:
menu = myMenuBar.addMenu("modules");
menu.addMenuItem({label:"Buffering", instanceName:"BufferingInstance"});
menu.addMenuItem({type:"separator"});
menu.addMenuItem({label:"Spatial Analysis", instanceName:"SAInstance"});

myListener = new Object();
myListener.change = function(evt){
	var itemSelected = evt.menuItem.attributes.instanceName;// Defines itemSelected as the instanceName of the selected menuItem.
	if (itemSelected == "BufferingInstance"){
		getURL("[URL unfurl="true"]http://www.google.com");[/URL]
	}else{
	trace(item.attributes.instanceName);
	}
}

menu.addEventListener("change",myListener);

I hope that helps to clear it up for you. It's really not hard at all once you get the process down. :)

Wow JT that almost looked like you knew what you were doing!
 
Fantastic, that has really cleared it up.

var itemSelected = evt.menuItem.attributes.instanceName;// Defines itemSelected as the instanceName of the selected menuItem.
if (itemSelected == "BufferingInstance"){
getURL("
this was the section that many of the Help guides were not explaining well. Have my menu up and running!

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top