PDA

View Full Version : Focus problems


kaiohon
06-01-2006, 02:42 PM
Inside a dynamically attached movie I have the following code
first_txt.onKillFocus = function(newFocus:Object) {
trace(this._name+" lost focus. New focus changed to: "+newFocus._name);
};
first_txt.onSetFocus = function(oldFocus:Object) {
trace(this._name+" gained focus. Old focus changed from: "+oldFocus._name);
}

THe text fiel is a multiline field. And contains some text, which later on will be cleared away on click. My problem is that as soon as i click somwhere outside the textfield it does not lose focus. The output looks like this

first_txt gained focus and null lost focus
undefined gains focus and _level0.sys1048576.first_txt looses focus
first_txt gained focus and null lost focus


This is cause by clicking inside the text field and then outside. What is the problem? I can't see it :(
PLEASE HELP!

astgtciv
09-27-2006, 07:43 AM
Bet you have a component in the library :D Seems to be this problem: http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21544177.html . Still no workaround for this, anyone?

astgtciv
09-27-2006, 08:25 AM
Well, if components must be used and you are having a terrible headache with an input textfield focus, one solution is to simply murder the focusManager which is causing all the problems:


_root.focusManager.removeMovieClip();


After that, your regular focus management will be back to normal. Some artifacts are introduced into the behavior of the components, but it doesn't look all that drastic (that is, if you are not relying on tabbed focusing, etc.). I hope there is a better way to do this, though...

astgtciv
09-27-2006, 08:38 AM
This solution seems to work pretty well for me so far (well I was only using a DataGrid, and its behavior looks to me so far unaffected by the untimely loss of the focusManager). Kudos to Mark Walters who posted the solution to chattyfig: http://chattyfig.figleaf.com/pipermail/flashcoders/2005-April/136345.html .

astgtciv
09-27-2006, 08:46 AM
Awww, found a cleaner version of the same, disabling the focusManager:


_root.focusManager.enabled = false;


No artifacts that I can see, and the focusing works fine. This must be a well-known problem, I wonder why it took me so long to find the solutions...

Kudos to Rich (juice002) (original thread:
http://groups.google.com/group/macromedia.flash.actionscript/browse_thread/thread/c24f4d6ffd26c292/f1a722d676c2d4af%23f1a722d676c2d4af).

Flash Gordon
09-27-2006, 08:47 AM
thanks for sharing ;)

astgtciv
09-27-2006, 08:47 AM
I'm just gonna add some keywords for the search engines to better index the thread:

textfield unfocus problem component focusManager focus

astgtciv
10-06-2006, 08:58 AM
I would like to note that in the setting focusManager.enabled to false solution, I do not succeed in removing focus from a textfield via Selection.setFocus(null) [the focus is not removed]. In the removing the focusManager movieclip solution removal of focus from a textfield via Selection.setFocus(null) does indeed work.

astgtciv
10-06-2006, 09:00 AM
That's funny, the docs say that FocusManager.enabled only turns tab handling on and off, not all of of FocusManager activity...

astgtciv
10-15-2006, 04:07 AM
Continuing the Focus Problem madness, the components start behaving really funny in terms of focus (e.g., in a ComboBox, the focus rectangle of a selected entry lingers on below the combobox after the selection has been made) when the component-containing swf is loaded into another swf. No, this happens whether the focusManager has been murdered as described above or not, and yes, it does happen even when _lockroot has been set to true for the component-containing swf (for if it is not, then all hell breaks loose).

One solution is to include a component in the library of the loader. However, the whole point of this exercise for me being to create a tiny external preloader, and the smallest component (Label) weighing in at 30K, this didn't fly. [This works, btw, because simply having a component in the library initializes the focusManager stuff automatically].

The next solution I tried was to attach a MovieClip linked to mx.managers.FocusManager to the _root of the loader. A little better, but the FocusManager still weighs a whopping 23K! Who knows what it pulls in... [This also works, btw.]

Finally the hack that I found to work around all this is a "compound" removal of the _root.focusManager. Nothing is being added to the loader swf, and in the component-containing loaded swf, I do


_root.focusManager.removeMovieClip();
_root.attachMovie("FManager", "focusManager", _root.getNextHighestDepth());
_root.focusManager.removeMovieClip();


In addition to this code you have to create a MovieClip in your library, assigning it the linkage name of "FManager" (or whatever you feel like, but then change the name in the code), and the AS2 Class of "mx.managers.FocusManager".

That's right - remove it, add it, remove it... the fun never ends. Seems to solve the problems though...

astgtciv
02-13-2007, 06:20 PM
A much simpler fix to the "strange focus rectangle behavior in components in swf's loaded into other swf's" (ooof :)) is to set


_focusrect = false;


in the top swf, the one that gets loaded into the browser first (in my case, a preloader).

Man, was this giving me a headache...

astgtciv
11-16-2008, 09:30 AM
Many years have passed... and I've found that setting _focusrect=false; doesn't always do the trick. Something depends on the order in which your components initialize. So, I've found another method - you can turn off all the focusrects for all the components with this:


// First set the theme to whichever one you'll use (e.g., "halo").
// Setting the theme sets the implementation of the "drawFocus" method on the UIComponent prototype.
// Since we don't want focus rects on our components (there is a bug in ComboBox focus rect drawing anyway),
// we remove it.
delete mx.core.UIComponent.prototype.drawFocus;