gmobj gives nasty error

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

gmobj gives nasty error

Post by stephan »

I get an error when i try a piece of code, was just wonder what im doing wrong.

Error:

'_m(...)' is null or not an object

Code:

with(milonic=new menuname("Main_Menu")){
style=Headers;
top=90;
left=18;
alwaysvisible=1;
orientation="horizontal";
itemheight="12px";
menuwidth="961";

aI("text=Help;itemwidth=80;");
}
drawMenus();
menuDisplay(gmobj("Main_Menu"),0);
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Stephan,

The problem is two-fold.

(1) Your use of the gmobj() function isn't quite correct. As you'll see in part (2) below, it turns out that you won't really need this function to use menuDisplay(), but just in case you need it in the future, let me explain how gmobj() works. You don't pass the name of the menu as you named it in your menu_data.js file; you have to use the "internal name". When the menus are built, each one is given an internal name or id that essentially numbers all of the menu consecutively. So, internally, those names are "menu1", "menu2", "menu3", etc. The trick to using gmobj() to get an object reference is knowing how to derive those internal names to target the right menu. The first part is easy: the text, "menu". Now you have to concatenate a menu number. The menu number is an integer that is the index into the _m[] array where the definitions for the menu in question are stored. You can get the menu number using the getMenuByName() function, like this:

Code: Select all

menuNum = getMenuByName("Main Menu");
So, to get an object reference to "Main Menu", you could do this:

Code: Select all

menuNum = getMenuByName("Main Menu");
menuObj = gmobj("menu" + menuNum);
You could, of course, combine that into one line, like so:

Code: Select all

menuObj = gmobj("menu" + getMenuByName("Main Menu"));
(2) The bigger issue is that your use of menuDisplay() isn't following the correct syntax. I don't think this is your fault, because you are following the syntax given on the methods reference page. The trouble is that I think the reference page provides the wrong syntax for using the menuDisplay() function (bummer there, right?).

Looking at the function itself, it seems to me like the first parameter passed to menuDisplay() should not really be a reference to a menu object. In other words, the first parameter should not be the return of a call to gmobj(), as shown on the reference page. Instead, the first parameter should be a menu number; an integer, as discussed in part (1) above. The menuDisplay() function then takes that number, and derives an object reference to the menu internally. You can supply the appropriate menu number using the return of the getMenuByName() function, as shown above. You could derive the menu number and call menuDisplay() in one line, like this:

Code: Select all

menuDisplay(getMenuByName("Main Menu"), 0);
Having said all that, it looks like you're trying to "turn off" your Main Menu as soon as the page loads. You'll run into another practical problem that'll prevent this approach from working even when the function calls are correct... a timing issue. When you call menuDisplay() immediately after drawMenus(), the browser won't have finished fully rendering the menus, so the Main Menu won't exist to turn off. The upshot: it won't work. You'd have to call menuDisplay() through a setTimeout() call and introduce a slight delay (allowing the menu to render). Problem there is that the slight delay would introduce a flash... the menu would appear briefly and then disappear. If you want the page to open without the main menu showing right away (e.g., maybe you want some user action to open the main menu), then it would be better to make the main menu not visible at first, then programatically set it to alwaysvisible and show it later.

That may have all seemed like overkill, but I thought it would be a good opportunity to explain how gmobj() and menuDisplay() work, so that others might find or be referred to this thread later. Meantime, I'll see if we can update the methods reference page to correct the description for menuDisplay().

I hope all that made sense!

Kevin
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

Your a genius

Post by stephan »

Thanks alot, that really worked! :D :D :D Was just wondering, how do I hide a menu on startup of the page? How do I change styles like onbgcolor and offbgcolor with a click of a menu item?
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Re: Your a genius

Post by kevin3442 »

Hi,
stephan wrote:...How do I change styles like onbgcolor and offbgcolor with a click of a menu item?
I'm not sure if you mean changing the property for a single item, or for an entire menu. If you're talking about changing an item property, you'll find a detailed description of a function I use called mm_changeItemProperty() in this thread. You should be able to use that function to change any property of any menu item programatically.

If you're talking about changing a menu property, I have a function for that too, but I don't think I've ever posted it in the forums. If you're interested, give a holler.

Cheers,

Kevin
ssalter
Advanced
Advanced
Posts: 12
Joined: Fri Jun 25, 2004 10:01 pm

Re: Your a genius

Post by ssalter »

kevin3442 wrote:.

If you're talking about changing a menu property, I have a function for that too, but I don't think I've ever posted it in the forums. If you're interested, give a holler.
Cheers,
Kevin
*waves* I"m interested! My main menu is defined as:

Code: Select all

with(milonic=new menuname("Main Menu")){
style=mainmenu;
alwaysvisible=1;
orientation="horizontal";
top=2;
left=10;
aI("text=Home;url=http://bl-iuhc-netsrv;");
aI("text=Phone List;target=ifr;url=http://bl-iuhc-netsrv/webtools/phonelist.asp;");
aI("text=ITS Help;target=ifr;url=http://bl-iuhc-netsrv/webtools/ithelp.asp;");
aI("text=Departments;showmenu=departments;");
aI("text=Resources;showmenu=resources;");
aI("text=WebTools;showmenu=webtools;");
aI("text=MY IUHC;url=javascript:showm();");
}
I want to "de-activate" all of the main menu items but "MY IUHC" when I click it once, then toggle them back on when I click it again. Is there a property for that? I couldn't find one.

I tried something from another thread:

Code: Select all

menuDisplay(getMenuByName("departments"), 0);
but it doesn't make the visible menu item vanish, just the underlying submenu which I verified by passing a "1" to the function call. It turns the submenu under Departments on and off.

I also looked at your function called "function mm_changeItemProperty" which is powerful but again, I don't see a property to DEactivate a specific menu item.

Thanks,
Steve
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

Post by stephan »

You’re a genius Kevin!
I get an object expected error when I use your function. I think it has to do with the update parameter. Here is a piece of my menu_data file:

Code: Select all

with(milonic=new menuname("Sub_Menu")){
style=Tabs;

aI("text=Settlement;");
aI("text=Terminal;url=javascript:mm_changeItemProperty('Sub_Menu','Settlement',7,'#ffffff','true');");

}


It does the changes but it does not take effect until you move the mouse over the item.

I still have a couple of questions that I know a genius like you can help me figure out.

(1) How do you single out borders like in css's(border-bottom: 1px solid #cccccc)?

(2)How do I make a menu start-up invisible?

(3)How do I make a menu item the width of the rest of the menu bar where the menu bar has a % for a width (menuwidth="95.5 %")?
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Steve,

Wow... a lot to reply to!
in an earlier reply, stephan wrote:*waves* I"m interested!
OK. Here's a function that will let you change a menu property (as opposed to a menu item property). A menu property will generally affect the entire menu.

Code: Select all

function mm_changeMenuProperty(menuName, propertyRef, newValue)
{
  var menuNum = getMenuByName(menuName);
  _m[menuNum][propertyRef] = newValue;
  BDMenu(menuNum);
}
The three parameters are:

(1) - menuName is the name of the menu you want to change.

(2) - propertyRef is the "property number" assigned to the particular property that you want to change, as shown in the Ref column of the reference page for menu properties. For example, the propertyRef for a menu's menuwidth property is 17.

(3) - newValue is the new value you want to assign to the specified property; a string or numeric value as appropriate, depnding on the property.

That's it. I don't think it applies to what you want to do (deactivate individual items), but there it is in case you want to use it in the future.
in an earlier reply, stephan wrote:I want to "de-activate" all of the main menu items but "MY IUHC" when I click it once, then toggle them back on when I click it again. Is there a property for that? I couldn't find one.
There is a property that might do what you want: the type property. If you set an item to type='disabled' then it "grays out" the item text and takes away it's functionality (you can still see it in its grayed-out form, but it doesn't do anything). You could set this for any item dynamically using the mm_changeItemProperty() function; the codeRef for the type property is 34.
stephan wrote:You’re a genius Kevin!
I'm not so sure about that... but thanks anyway!
stephan wrote:I get an object expected error when I use your function. I think it has to do with the update parameter.
I think your thinking is probably correct. In your call to mm_changeItemproperty(), you pass 'true' for the updateDisplay parameter (fourth param). You've passed it as a string, but it should be a boolean. Try removing the single quotes, i.e. pass true with no quotes. Alternatively, you could simply pass a 1 (for true) or a 0 (for false).
stephan wrote:How do you single out borders like in css's(border-bottom: 1px solid #cccccc)?
You could try the rawcss property (although that had some issues a few builds ago... haven't tried it for awhile).
stephan wrote:How do I make a menu start-up invisible?
I assume that your ultimate goal would be to have an intended "main menu" start out invisible, then open it at some later point. Correct? This might work. In your men_data.js file, set the menu's alwaysvisible property to 0 (or don't set it at all). Later, when you want to "turn it on", use the mm_changeMenuProperty() function to set the menu's alwaysvisible property (propertyRef is 7) to 1, then use the menuDisplay() function (as you have already tried) to display the menu. Once the menu is displayed, it should remain visible. if that doesn't work there are other possibilities.
stephan wrote:How do I make a menu item the width of the rest of the menu bar where the menu bar has a % for a width (menuwidth="95.5 %")?
I'm afraid I don't know what you mean with this one. Can you explain your goal a little more?

Cheers,

Kevin
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

almost there

Post by stephan »

The boolean was not the problem I did a little manual debug and cornered the line that gives the error, its the "BDMenu(_mi[0])" function call, maybe I have an older version for the menu. Any ideas?


The always visible worked nicely, thanks.

About the menu width problem. My idea was to make a menu that spans over 90% of the page like you do with div's. Then I want the menu items to start from left and sit tightly next to each other without huge spaces. Ill put a screenshot in to explain how I want my meny to look. The problem with the current setup is that if the page changes size the menu stays the same size and it looks wierd.

Image
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

You can set the itemwidth within each item aI string as a percentage.

Ruth
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I've done a little more testing with version 5.45 and using the code you posting in the first post. To get the menu the way you want it you would put this:

Code: Select all

with(milonic=new menuname("Main_Menu")){ 
style=Headers; 
top=90; 
left="offset=5%";
screenposition="center";
menuwidth="90%";
alwaysvisible=1; 
orientation="horizontal"; 
itemheight="12px"; 
align="left";
This would position the menu 5% centered in the page. I don't know why but it will not work if you do not have both screenposition="center"; and the left="offset=5%";

Ruth
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

Post by stephan »

Thanks Ruth. It’s working nicely except that there isn’t a 5% offset on the right as well. I did the itemwidth as you said, I have 3 items so I made them all 10% and I put a dummy one in with 70%. As soon as you put itemwidth in, it ignores the menuwidth and if you put itemwidth’s in it has to amount to 100% else it ignores the itemwidth’s. I was wondering if I could put a link to my menu_data and you could take I look at it.


http://www.weddingworld.org.za/menu_data.js
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

Post by stephan »

I checked through all the functions in all my .js files and I went through Ruth's webpage's .js files (Just because I know you should have the latest version of the menu), I can’t find a BDMenu function. Where do I get it?




_____________________________________________________________
Nice website Ruth ;) ;)
_____________________________________________________________
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Hi Stephan,
stephan wrote: I can’t find a BDMenu function. Where do I get it
I don't know about functions. That is part of the program files in the menu. You are not supposed to modify any of the program files, you won't get support for the menu if you do, after all if you change the programming, we wouldn't have a clue how to support what you did nor whether it would allow all the other things to function as they should since the program codes interact .
stephan wrote:I went through Ruth's webpage's .js files (Just because I know you should have the latest version of the menu),
:oops: Not a good choice, I've not updated until I get time to test all the strange things I've got in the css with the new versions.
stephan wrote:It’s working nicely except that there isn’t a 5% offset on the right as well.
You wouldn't specify the right since you are using percentages the right side would automatically be whatever percentage is remaining: left offset=5%, menuwidth=90%, right would be the remaining 5%.
stephan wrote:I did the itemwidth as you said, I have 3 items so I made them all 10% and I put a dummy one in with 70%. As soon as you put itemwidth in, it ignores the menuwidth and if you put itemwidth’s in it has to amount to 100% else it ignores the itemwidth’s
I'm sorry, my fault for not explaining on my second post. If you use the menuwidth="90%" you can't use a percentage in the item width. As you found out it wants the itemwidths when in percentages to = 100%. You can specify an absolute itemwidth even with the menuwidth="90%". I'm not sure why you'd want to specify width at all, since without a width specified, and with the menuwidth at 90%, the menu items align to the left and leave all the extra space at the right.
stephan wrote:Nice website Ruth
Thanks :D

Ruth
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

Post by stephan »

I did it exactly like you said and my menu is sitting, snug and short, in the middle of the page. I don’t know what I am doing wrong :( :(


Kevin wrote:

Code: Select all

function mm_changeMenuProperty(menuName, propertyRef, newValue) 
{ 
  var menuNum = getMenuByName(menuName); 
  _m[menuNum][propertyRef] = newValue; 
 BDMenu(menuNum);
}
I didnt want to change anything, I was just looking for the BDMenu function, clearly if he calls a function it should be in one of the .js files that I include. I was just checking if this BDMenu was released after version 5. I still cant use the function quoted above.
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Steve,

BDMenu() is part of the menu system's source .js files (i.e., it's a built-in function).

mm_changeMenuProperty(), on the other hand, is a function I wrote. I've used it lots of times, in lots of browsers, with no problem. What is it you're trying to do with it, and in what browser/OS?

Kevin
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

*shrug*

Post by stephan »

Okies, I made a testing page with my menu:
http://www.weddingworld.org.za/testing/test.html
:) :)
I am on windows Xp and using IE6.

Ruth do you mind taking a look at my layout problem while we have a working test going?
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I can easily solve all the problems...well maybe :) Update your menu. You can't find BDMenu because it doesn't exist in the version you are using which is soooooo far behind where we are. It's almost a year old and is a beta version, not even the final release. If you update, BDMenu exists and the function will most likely work, and the menu will be as you want it in the layout.

Ruth
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

Post by stephan »

Thanks a lot all, my problems are all fixed, except the rawcss one but that is another thread. You are all geniuses!!!!
Now I am one step closer to world domination!
:} :} :} :} :} :} :}
stephan
Advanced
Advanced
Posts: 14
Joined: Tue Aug 31, 2004 3:23 pm

Post by stephan »

:( :( :( :( :( :(
Finally got my menu looking good and then I realized that the changes I make with kevin's brilliant function only lasts until you press submit. Then it reverts back to what the styles tells it to be. What now?
*shrug*
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

What is it you are trying to do?

Kevin
Post Reply