all groups > flash actionscript > september 2004 >
You're in the

flash actionscript

group:

MenuBar


MenuBar myckelh
9/10/2004 10:01:47 PM
flash actionscript: I understand that the menuBar component is ment to be used as a menu.
However, I would like to Not add the dropdown list to it, and just use the bar
as if the menu lables were buttons..

Example: where it says labels in the component parameters, I have added the
following:
Feedback, Survey, contact ---- so it looks like a regular menu without any
dropdown selections.

What I want to happen:
When user clicks on feedback? .I?ll load / attach or do whatever

if I could capture the lables name I can do the other stuff however, i dont
know how to get that name.

I tried:
on(change){
var lable = this.value;
trace(lable);
}

nothing gets traced .. I also, tried data, lable,



Re: MenuBar pigpen_88
9/11/2004 10:12:16 AM
What you are trying to do, using the menubar top level items (it's labels) as
buttons is actually one of the weaknesses of the component. For submenu's its
great and for using xml data to dynamic create the submenus and labels.

However there is an undocumented workaround that uses a "menuShow" method.
First, don't use the component parameters to enter you label text. You'll have
to add it with actionscript (code is below). Name your menubar component
"myMenuBar" and try this code that is based off an example from the user
comment section of the excellent (but currently offline) menubar component
tutorial by Darron Schall.

// menubar component with an instance name, myMenuBar
var label1_menu = myMenuBar.addMenu("Google");

var label1Listener = new Object();
label1Listener.menuShow = function(event) {
trace("You clicked on label1");
getURL("http://www.google.com", "_blank");
};

label1_menu.addEventListener("menuShow", label1Listener);

This works, however you'll notice that your menu buttons stay selected
(highlighted) despite your mouse no longer being over the item. For some
people, that annoying, as this visual behavior does not happen with the
submenus. Further proof that the menubar component was designed for submenu
use. =/ The other worry about this method, is that I'm not sure if it'll work
with xml data. While you can use xml data to dynamically populate the labels,
I'm not sure if there is a dynamic way to make the methodShow option work as
well, atleast not without some additional coding. There may be a way to visual
fix the highlight issue, by delving into the UI code for components and
skinning, but I haven't tried.

Anyway, I hope that works for you. Another method, and not to mention easier,
is to just use the menubar component as a visual aid for you buttons, and put
text buttons directly over the menubar. This way you'll have more control over
your buttons and won't have the "highlighting" bug mentioned earlier.







Re: MenuBar myckelh
9/13/2004 5:55:09 PM
Thats great thanks.

If its not too much trouble, can you write me the code for two items on the
menu bar.

I tried doing the following:
but there was some problems.
When you click on one lable it works, however as you scroll over the other
lables it starts running the scrip as if I have selected the item.

Also, I'm not undersatnding the function(event) -- what does that do?
// menubar component with an instance name, myMenuBar
var label1_menu = myMenuBar.addMenu("Contact");
var label2_menu = myMenuBar.addMenu("Feedback");

var label1Listener = new Object();
var label2Listener = new Object();

label1Listener.menuShow = function(event) {
trace("You clicked on label1");
//getURL("http://www.google.com", "_blank");
};

label3Listener.menuShow = function(event) {
trace("You clicked on label2");
//getURL("http://www.myckelh.com", "_blank");
};


label1_menu.addEventListener("menuShow", label1Listener);
label2_menu.addEventListener("menuShow", label2Listener);

Thanks again for the help
Re: MenuBar pigpen_88
9/14/2004 3:57:26 AM
yeah that was the annoying "bug" that I mentioned. As far as I could tell, I
don't think there is any easy solution to solve that. I've messed with
menu.change, menu.hide, menu.menuHide, etc and I came to the conclusion that
the only way to "un-highlight" a top level menu item, was to click somewhere
else. The menu.change event only registers when a submenu item is clicked and
which will then "un-highlight" the menu as a whole. Reason why this was an
undocumented method.

Probably, digging deep into the components guts itself and actually rewriting
some of the component behavior is what is needed. But, you might be better off,
just using the component as a graphic background and make your own buttons on
top of it, since all your really doing is making rollover buttons. Whole point
of that component is to use submenus.

Sadly, there should be more documentation on this. Several other posters in
the past here have expressed to Macromedia that they should make this menu
component handle top level clicks in a better fashion.




Re: MenuBar myckelh
9/14/2004 11:30:23 PM
It's not the hiding the highlighted button that I'm worrined about.

what happens to me, is that once you click on one button -- the rest take an
"Overstate" meening. when I put my mouse over the other lables on the menubar,
it starts trigiring the script and start geting the url. I want to be able to
click on it.

is that what you ment? or did you meen, the button that is clicked on stayes
in the over state (look wise)
Re: MenuBar pigpen_88
9/15/2004 8:01:55 AM
yeah I meant both. menuShow solution I told you was a hack. A workaround, so
thats why its giving you annoying results, like that script executing on
rollovers of other buttons. Hopefully there will be an upgrade or some
documention to hidden inner workings of that component.
Re: MenuBar pigpen_88
9/15/2004 12:19:17 PM
Good news! There's another solution, bad news, yeah its undocumented as well.
But the good thing, it works! Much better than the menuShow workaround. Credit
goes to Jotun75, who sent me this solution, after I had asked on another site
for about the component. He said its not documented by Macromedia at all.

// name your menuBar component, "myMenuBar"
var label1_menu = myMenuBar.addMenu("home");
myMenuBar.mbItem200.onPress = function(){
trace("you clicked on Home");
}
var label2_menu = myMenuBar.addMenu("about");
myMenuBar.mbItem201.onPress = function(){
trace("you clicked on About");
}

Notice that mbItem200 targets your first label, and then mbItem201 targets the
second label, and so on. So you can keep making new menu labels and just target
them using mbItem20x. Voila! and no more annoying rollover issues.
good luck.





AddThis Social Bookmark Button