I want to create a tab-enabled popup window in an AS3 Air project. Currently, when I press tab several times, the focus goes through all the components in my popup window and then starts focusing the buttons and TextFields from the components that are behind the popup. I have tried to solve this problem in two ways, but none of them worked. I will explain both of the methods here
The official method
I have read adobe's documentation from here and it describes what I should do in my case like this:"Each modal Window component contains an instance of the FocusManager, so the controls on that window become their own tab set. This prevents a user from inadvertently navigating to components in other windows by pressing the Tab key. " But I still don't understand how to use the FocusManager.
- I have tried creating 开发者_运维百科an instance of the FocusManager in each of my view component classes by putting the code below in the constructor, but it didn't work:
_focusManager = new FocusManager(this);
- What do they mean by "modal Window component" ?
The workaround method
Another thing I've tried is to manually set the tabEnabled property to true or false on each button and TextField when the Parent component dispatches a FOCUS_IN or FOCUS_OUT event. This worked on a simple example that I created on a new flash file, but it doesn't work on my large project, and I don't know how to debug it. However I would be very glad to dump this and go back to method number 1.
Has anyone encountered these problems before? Have you used multiple tab cycles in any other way? Any hint is welcome right now, because I've been wasting too much time on this problem. Thank you [Edit] I was getting a lot of views for this question, but no relevant answers, so I edited it and tried to simplify it
Yeah tabbing can be a real pain.
I had a similar problem, where tabbing stopped working after I had a popup open. Problem was that the popup was alive in the background and hijacked the tabbing.
This solved my problem, with individual tabcycles now working for main app and popups:
// my popupclass
protected var fm:FocusManager;
public function show( centered:Boolean = true, parent:DisplayObject = null, modal:Boolean = true ):void {
// some code
fm = new FocusManager( this );
fm.activate();
}
public function hide( closeType:int = 1 ):void {
// more code
fm.deactivate();
}
Depending on what you are trying to achieve, you maybe able to use tabIndex instead of the FocusManager.
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/InteractiveObject.html#tabIndex
I ended up writing my own FocusManager which does what I need. It turned out to be easier than I initially thought. I'm sorry to say that I can't post the code here, but I'll give you a short description of what I did and hope that it helps:
- I implemented the fl.managers.IFocusManager interface, but I didn't entirely respect the way the old manager worked
- The constructor of my CustomFocusManager requires an array of the tabbable children as parameter, and the children have to be in the order that they will appear in the loop. In this way I did not have to care about the type of the children (is it tabbable or not?) or ask myself if tabIndexes exist or not.
- I ignored the tabIndex properties
- I created a new interface called IFocusManagerContainer, inspired from the Flex interface with the same name
- I created a static class similar to Flex's SystemManager which knows when to activate/deactivate the FocusManagers depending on the children found on the stage.
I took a peek into the mx.managers.FocusManager code, and from what I saw, most of their effort was put into handling all the possible cases where the FocusManager might be used, this is why it's so long and complicated. I can only assume that fl.managers.FocusManagers looks similar. I bet that mine still has a lot of problems, and it isn't as portable as the ones from Adobe, but it's very simple and it does what I need it to do.
I would still like to see some guidelines on how to correctly use the existing FocusManager.
精彩评论