8 Replies Latest reply on Dec 16, 2008 8:38 AM by Newsgroup_User

    Get a button to respond to Enter key?

    Handycam Level 1
      I have an interface that has a panel with a control bar that has 2 buttons, "next" and "previous". I'd like to have the Enter key be the same as pushing the "next" button. How can I go about this?
        • 1. Re: Get a button to respond to Enter key?
          Level 7

          "Handycam" <webforumsuser@macromedia.com> wrote in message
          news:gi5v08$v8$1@forums.macromedia.com...
          >I have an interface that has a panel with a control bar that has 2 buttons,
          >"next" and "previous". I'd like to have the Enter key be the same as
          >pushing the "next" button. How can I go about this?

          If they're in a container, you can set next as the defaultButton.

          HTH;

          Amy


          • 2. Re: Get a button to respond to Enter key?
            rtalton Level 4
            Check the help docs under FocusManager, and its defaultButton property. I think this is what you need.
            • 3. Re: Get a button to respond to Enter key?
              Handycam Level 1
              Yes, I have tried:
              <mx:HBox width="100%" defaultButton="nextBtn">

              But get an error:
              Initializer for 'defaultButton': values of type mx.core.IFlexDisplayObject cannot be represented in text.

              I have no idea what this means.
              • 4. Re: Get a button to respond to Enter key?
                Level 7

                "Handycam" <webforumsuser@macromedia.com> wrote in message
                news:gi61r3$4mk$1@forums.macromedia.com...
                > Yes, I have tried:
                > <mx:HBox width="100%" defaultButton="nextBtn">
                >
                > But get an error:
                > Initializer for 'defaultButton': values of type mx.core.IFlexDisplayObject
                > cannot be represented in text.
                >
                > I have no idea what this means.
                >

                defaultButton="{nextBtn}"


                • 5. Re: Get a button to respond to Enter key?
                  Handycam Level 1
                  Yes, I then tried that and the error goes away -- but nothing happens.

                  I have tried putting on the parent Canvas, and even adding event listeners. The button works, but the enter key does nothing. See attached:

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%" defaultButton="{nextBtn}">

                  <mx:Script>
                  <![CDATA[
                  import mx.core.Application;
                  import mx.managers.FocusManager;

                  [Bindable]
                  public var app:Object = Application.application;

                  public function stepInit():void { // called from the parent application, I know it is being called
                  nextBtn.addEventListener(MouseEvent.CLICK,goNext);
                  }


                  private function goNext(e:MouseEvent):void {
                  Application.application.nextStep()
                  }

                  ]]>
                  </mx:Script>

                  <mx:Image id="stepImage" bottom="8" x="20" />

                  <mx:VBox x="20" y="20" width="500">
                  /* text objects */
                  <mx:HBox width="100%">
                  <mx:Button id="nextBtn" label="Start building your recipe now!" click="goNext(event)" styleName="normalButton"/>
                  </mx:HBox>
                  </mx:VBox>

                  </mx:Canvas>
                  • 6. Re: Get a button to respond to Enter key?
                    Handycam Level 1
                    Any more thoughts on this? I am confused, since the docs (and posts here) seem to indicate I can set this property on container, but so far no luck.

                    Does this only work with form containers? Are any containers? Do you need to add an event listener to something (the button? the container?) or when it works it just uses the exiting button click event handler?

                    I have tried a few experiments and can't get this to work. It would be most handy if I could. Thanks.
                    • 7. Re: Get a button to respond to Enter key?
                      Guddie
                      In my experience, I needed to first add a Form, then Form Items, with the button being a child, in order to be able to use it as a default.
                      • 8. Re: Get a button to respond to Enter key?
                        Level 7

                        "Guddie" <webforumsuser@macromedia.com> wrote in message
                        news:gi8eh9$8nr$1@forums.macromedia.com...
                        > In my experience, I needed to first add a Form, then Form Items, with the
                        > button being a child, in order to be able to use it as a default.

                        I've used it from a VBox with no problem whatsoever.