5 Replies Latest reply on Jun 28, 2011 8:39 AM by Flex harUI

    Keyboard shortcut difficulties

    tehxike1 Level 1

      I'm not sure what to do about this...  If my component implements IFocusManagerContainer, I can tab from field to field.  If it implements IFocusManagerComponent, keyUpHandler is called, so I can handle keyboard shortcuts.  But they're mutually exclusive- I can't have both.  Either tabbing works, or keyUpHandler works.  Implementing both interfaces still prevents tabbing from working.  How can I get both of these rather basic features to work at the same time?

        • 1. Re: Keyboard shortcut difficulties
          Flex harUI Adobe Employee

          Most folks use keyDown.  Why are you using keyUp?  KeyUp should still work

          for IFocusManagerComponent.  When does it not work?

          • 2. Re: Keyboard shortcut difficulties
            tehxike1 Level 1

            Not sure why I picked keyUp...  keyDown does work as well...  But this is a really easy problem for me to reproduce.  Running the following application...  If I implement the IFocusMangerComponent interface, keyDown is called, but tabbing doesn't work.  If I don't, keyDown isn't called, but tabbing works.

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <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"

               implements="mx.managers.IFocusManagerComponent">

            <fx:Script>

            <![CDATA[

            override protected function keyDownHandler(event:KeyboardEvent):void

            {

            super.keyDownHandler(event);

             

            if (event.ctrlKey && event.keyCode == Keyboard.S)

            {

            label.text = "Save Detected";

            }

            }

             

            ]]>

            </fx:Script>

             

            <s:layout>

            <s:VerticalLayout />

            </s:layout>

             

            <s:TextInput />

            <s:TextInput />

            <s:Label id="label" />

            </s:WindowedApplication>

            • 3. Re: Keyboard shortcut difficulties
              Flex harUI Adobe Employee

              A container (like the app) should not normally be an IFocusManagerComponent

              because it should never really have focus, its children like the TextInputs

              should.

               

              Keyboard events bubble, so once a TextInput has focus, they keyDownHandler

              should be called in the application.

               

              If nothing has focus, keyboard events are dispatched from the stage, so you

              may also need to listen there.

              • 4. Re: Keyboard shortcut difficulties
                tehxike1 Level 1

                Ah, makes sense.  Is adding/removing the stage event listener in added_to_stage/removed_from_stage the best way to implement this and avoid a memory leak?

                • 5. Re: Keyboard shortcut difficulties
                  Flex harUI Adobe Employee

                  I use a weak reference listener to systemManager.stage during app

                  initialization.