4 Replies Latest reply on Mar 5, 2012 10:06 AM by Flex harUI

    Set focus on image component + IFocusComponent

    PagePageUI

      Hello,

       

      Is there a way i can set focus on an image component? I tried to use the IFocusManger it did not work for images but worked for buttons and TextInputs. When i read the API for IFocusManager, it says it can set the focus on any component and since an image is a component, it think it should work but it isn't working. Am i missing something? Thanks for your help.

        • 1. Re: Set focus on image component + IFocusComponent
          PagePageUI Level 1

          Here's a sample of my code

           

          MainApplication.mxml     

          //this is the code in the script block

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

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

          ....

          ....

          switch(key)

                          {

                              case Keyboard.LEFT: //left keycode: 37

                              {

                                  if((pattern.indexOf("content_container")) > 0)

                                  {

                                      IFocusM.setFocus(nav_content_container[elem_id].left);

                                      drawInitialFocus(nav_content_container[elem_id].left);

                                      IFocusM.getFocus().drawFocus(true);

                                      focused_component = String(IFocusM.getFocus());

                                      trace('Focus is now on ' + focused_component);

                                  }

           

          ....

          ....

          //this is the mxml code in the MainApplication.mxml

          <s:TileGroup id="content_container"

                           width="700" height="100%"

                           horizontalGap="20" verticalGap="20">

                  <s:Image id="first" width="200" height="250" source="images/charlottes_web.jpeg"/>

                  <s:Imageid="second" source="images/bad_lieutenant.jpeg"/>

                  <s:Imageid="third" source="images/caroline.jpeg"/>

                  <s:Imageid="fourth" source="images/che.jpeg"/>

                  <s:Imageid="fifth" source="images/date_movie.jpeg"/>

              </s:TileGroup>

          </s:Application>

           

          Please help me out if you can. If this isn't possible, let me know and i will stick to using buttons as my components

          • 2. Re: Set focus on image component + IFocusComponent
            Flex harUI Adobe Employee

            I’m not sure how to help from that code snippet.  First, why do you want to set focus to an Image?  Focus is for choosing which component gets keyboard input.  What would the user type when focused on a component?  Are you trying to implement a selection model instead?  Maybe use a List or add keyboard handlers to the systemManager and draw highlights around the images.

            • 3. Re: Set focus on image component + IFocusComponent
              PagePageUI Level 1

              Flex harUI,

               

              Thanks for your help. The reason why i want to set focus on an image is because i want a user to know what is highlighted. Based on what is highlighted, i'll display the property of the image. I definitely like your suggestion about drawing an highlight on an image (i'll look into that). But the issues i am having is that i wrote my own keyboard navigation because that's the only way the user can navigate my app. So here's the scoop:

               

              1. The focus is set to the button that has focus

              2. All the buttons have their icon property set. So i used this to make the user feel they are looking at an image when it is really an image embeded in a button

              3. Based on what arror key the user presses, the focus is set on the button

               

              Do you think i can achieve the same result while using the systemManager to draw highlishts around the images? Thanks again for your help!

              • 4. Re: Set focus on image component + IFocusComponent
                Flex harUI Adobe Employee

                I wouldn’t use systemManager.  I would subclass Image and add the ability to draw a highlight, then set a single keyboard event listener on systemManager and use it to change the highlights on those Image subclasses.  No need to set focus to them.