Search code examples
actionscript-3apache-flexairflex4

NativeMenu not appearing on Windows


I feel foolish asking this question but I've spent 2+ hours trying to solve it with no joy.

I am simply trying to get some native menu to show up on Windows. I wrote my own code and that works on OSX but no menu appears on windows, so I searched around for examples ad have tested a half dozen including this one from Adobe.

There is nothing special in what I am doing. The NativeWindow system chrome is standard, etc. I am testing this on OSX running VMWare with Windows 7 – but most things seem to work fine. I put in a trace statement which indicated that the menu was getting created on Windows.

Does anyone know what could prevent a menu getting created on Windows in a Flex WindowAplication?

        private function initMenu():void
        {
            if( NativeWindow.supportsMenu){
                stage.nativeWindow.menu = createAppMenu();
            } else if( NativeApplication.supportsMenu ){
             NativeApplication.nativeApplication.menu = createAppMenu();
            }
        }


        private function createAppMenu():NativeMenu
        {
            var myMenu:NativeMenu = new NativeMenu();

            var nameMenu:NativeMenuItem = myMenu.addItem( new NativeMenuItem( "Window World" ) );
            var aboutMenu:NativeMenu = new NativeMenu();
            var aboutMenuItem:NativeMenuItem = aboutMenu.addItem( new NativeMenuItem( "About" ) );
            nameMenu.submenu = aboutMenu;

            var fileMenu:NativeMenuItem = myMenu.addItem( new NativeMenuItem( "File" ) );
            fileMenu.submenu = buildFileMenu();

            return myMenu;
        }

        private function buildFileMenu():NativeMenu
        {
            var fileMenu:NativeMenu = new NativeMenu();
            var closeAppMenu:NativeMenuItem = fileMenu.addItem( new NativeMenuItem( "Exit" ));
            closeAppMenu.addEventListener( Event.SELECT , closeApp );
            return fileMenu;
        }

Solution

  • The whole Flex thing can be so annoying...

    The reason the menu wasn't showing up was because I was using the creationComplete event. Switching to windowComplete is the correct event to use.

    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                           xmlns:s="library://ns.adobe.com/flex/spark" 
                           xmlns:mx="library://ns.adobe.com/flex/mx"
                           width="1024" height="768" 
                           showStatusBar="false"
                           windowComplete="initMenu(this)" >