PDA

View Full Version : onKillFocus() getFocus()


tobyw_1969
04-22-2005, 11:34 AM
What is going on with this?

TextField.prototype.onKillFocus = function(){

trace (Selection.getFocus());

}

Why is the selection the text field, when we have just killed focus? Is it because of the order that setFocus and killFocus happen in?

Is there no way to find out which movieClip has been pressed immediately after the focus being in a textField? I tried using the newFocus property like this

TextField.prototype.onKillFocus = function(newFocus:Object){
trace("newFocus=" + newFocus);
}

but it always returns null unless you focus on another textField. MovieClips don't work in spite of Macromedia LiveDocs saying they do. Anyone know how to find out what the new focus is?

Taff
04-22-2005, 01:32 PM
Hazarding a guess, I would say that even though its being killed onKillFocus it still actually has focus
If I place a small setInterval in there and tab through them it appears to work, nasty solution though...if you can call it a solution :/

TextField.prototype.onKillFocus = function(){
intID=setInterval(function(){
trace (Selection.getFocus());
clearInterval(intID);
},200);
}
foo2.tabIndex=3;
text1.tabIndex=1;
text2.tabIndex=2;

Whats the newFocus property?

Taff

tobyw_1969
04-22-2005, 02:08 PM
This is the MM documentation for onKillFocus explaining the (alleged) function of newFocus. It only seems to kick in if the object receiving focus is another textField.

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary753.html

Like a lot of the Selection related stuff it doesn't actually do what it says in the documenation. Another example is setFocus(null) which they claim will remove focus from the current selection but doesn't. Well, I suppose it only costs £1000 pounds or so - what can you expect? ;)

I tried the setInterval thing too - but it goes against my moral principles to use setInterval unless someone's life is in danger. I managed to find a way to avoid using setFocus altogether anyway, which is probably the best advice to anyone trying to use it. heh.

Taff
04-22-2005, 03:19 PM
Yep, I never noticed that it was you who posted Toby, or I wouldnt have offered the setInterval advice :-)

Stay safe!