4 Replies Latest reply on Feb 10, 2012 8:51 AM by Rodster002

    Global Event Listeners for all Views in a ViewNavigatorApplication

    Rodster002

      Hello,

       

      As the subject states, I have a ViewNavigatorApplication and I am trying to set up a "global" event listener for all views. Which I am able to do, however I am having problems...

       

      In my first view, I assign this listener:

      NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys);

       

      And I also have this function:

       

      public function handleKeys(event:KeyboardEvent):void {

       

           if (event.keyCode == Keyboard.MENU) {

                          trace("menu pressed");

                          navigator.pushView(MainMenuView);

                }

      }

       

      This works fine from the first view. But when I switch views, I get an exception on pushView (navigator is null). I think I understand why, so what is the best practice for something like this? How can I get access to the spark component navigator from that function when called from a different view? Or is there a better way to go about this?

       

      Thank you!