0

I'm currently building a Flex 4.5 mobile project including several views and custom written MXML components that can be incorporated dynamically into those views. How do I determine which component currently has focus, namely has been activated by the user tapping on it? The background for this is a global search function in the main application. Depending on the results of this search, fields in the custom components are set. Given that I don't want all components in a view to listen to the outcome of that search function, I have to check which one is currently active. I'm trying to bind the selected object (the result from the search function) to the active component.

Any help would be much appreciated.

Cheers!

AlBirdie
  • 2,071
  • 1
  • 25
  • 45
  • Actually, the solution was quite simple; Each component calls a function dispatched by a click event (works for both mobile and desktop). This function checks which component has been selected (MouseEvent.currentTarget) and calls a stateChanger method in each component which actually changes the state. – AlBirdie Nov 28 '11 at 15:00

1 Answers1

1

You can determine which component currently has focusing using the FocusManager.getFocus(). Conceptually something like this:

var ComponentWithFocus : IFocusManagerComponent= FocusManager.getFocus();
JeffryHouser
  • 39,401
  • 4
  • 38
  • 59
  • Thanks for your reply Jeffry, unfortunately the focusManager isn't really suitable for my problem (or at least I don't see how). Given that I have to use this for a global search function, the search field is always the component with focus. So unless I'm completely fishing in the dark here, I'm sticking with my MouseEvent method, which actually works fine (for now). – AlBirdie Nov 29 '11 at 08:29
  • I believe my answer properly answers your question, of "how do I determine which component currently has focus." Maybe you asked the wrong, or incomplete question. However, if you feel you have the proper answer; you should answer your own question formally and select it as such. In a MouseEvent, the currentTarget is the component that assigned the event listener. It may not relate to focus. More information about the difference between target and currentTarget in events: http://stackoverflow.com/questions/5921413/difference-between-e-target-and-e-currenttarget – JeffryHouser Nov 29 '11 at 17:28
  • Well, sometimes it's hard to define exactly what you need when you just started with Flex ;). But yes, you're totally right, you answered the question correctly. Thanks for your detailed information on this topic. I have to admit, it can get a little confusing. – AlBirdie Nov 30 '11 at 15:36