3 Replies Latest reply on Aug 7, 2008 3:33 PM by Newsgroup_User

    Custom MenuBar

    YushengWang Level 1
      Hello:
      I am creating a custom menu bar with accelerator keys. I created two subclasses called MyAcceleratorMenuBar and MyMenuItemRenderer. MyAcceleratorMenuBar is a subclass of MenuBar and MyMenuItemRenderer is a subclass of MenuItemRenderer. For the first step, I did not add any logic to MyMenuItemRenderer just want to test if I can use
      a custom item renderer. But I found a very strange error when tired to run my code. I am new to flex and really don't know where the code is wrong. I appreciate any help.

      Thanks
      Yusheng
        • 1. Re: Custom MenuBar
          RustyRathbone Level 1
          I have done that same thing and am having similar problems. I have my own MenuBar that does the same thing. When I comment out the line that sets the itemRenderer it all works fine. I have even tried setting the item renderer like this:

          // default item renderer from Adobe
          menu.itemRenderer = new ClassFactory(MenuItemRenderer);

          But that fails too. There is obviously something else needed in order to get this to work.

          The error is a null reference error. You have to run it in debug mode to see it. If you do not you only see screwed up behavior in the menu. Here is the error I get:

          TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at mx.controls.listClasses::ListBase/drawItem()[E:\dev\3.0.x\frameworks\projects\framework\s rc\mx\controls\listClasses\ListBase.as:4906]
          at mx.controls::Menu/drawItem()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\M enu.as:1202]
          at mx.controls::Menu/hide()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\controls\Menu. as:1511]
          at mx.controls::Menu/ http://www.adobe.com/2006/flex/mx/internal::hideAllMenus()[E:\dev\3.0.x\frameworks\project s\framework\src\mx\controls\Menu.as:2178
          at mx.controls::Menu/keyDownHandler()[E:\dev\3.0.x\frameworks\projects\framework\src\mx\cont rols\Menu.as:2012]

          • 2. Re: Custom MenuBar
            RustyRathbone Level 1
            OK. I have looked at this some more. Certainly there are some private (mx_internal) methods in MenuItemRenderer that would not be available in some subclass. I copied the entire MenuItemRenderer class into a new class (MyMenuItemRenderer) and started from there. This spawned a process of having to create a bunch more classes. I created a new MenuBar too. And I had to make a new Menu. Then MenuEvent. Then...then...then...

            This is getting crazy. I must be doing this wrong. I would really like to hear from somebody at Adobe or anybody who knows how to do this and have it work.
            • 3. Re: Custom MenuBar
              Level 7

              "RustyRathbone" <webforumsuser@macromedia.com> wrote in message
              news:g7f9ri$397$1@forums.macromedia.com...
              > OK. I have looked at this some more. Certainly there are some private
              > (mx_internal) methods in MenuItemRenderer that would not be available in
              > some
              > subclass. I copied the entire MenuItemRenderer class into a new class
              > (MyMenuItemRenderer) and started from there. This spawned a process of
              > having
              > to create a bunch more classes. I created a new MenuBar too. And I had to
              > make
              > a new Menu. Then MenuEvent. Then...then...then...
              >
              > This is getting crazy. I must be doing this wrong. I would really like to
              > hear
              > from somebody at Adobe or anybody who knows how to do this and have it
              > work.

              You can just set menuBarRenderer, so you shouldn't need to rewrite MenuBar
              to use a new renderer, unless there was something specific you needed to
              add. I would think you could also use the existing MenuEvent, again unless
              the one Adobe made needed more to do what you want.

              Looks like the default menuBarItemRenderer is actually a MenuBarItem, not a
              MenuItemRenderer. You may want to check to see if you've imported the
              definition for whatever you're using, but I think that gives a different
              error.

              HTH;

              Amy