views:

53

answers:

1

This is driving me insane. I am working in Flash (not Flex) with Actionscript 3. I have an instance of the class SimpleButton. I have a TextField that I don't want to lose focus when the user clicks my SimpleButton. It is my understanding that both Actionscript 2 as well as the Flex class 'Button' both have a settable/gettable property called "focusEnabled". I can't seem to find an equivalent for Flash Actionscript 3's SimpleButton. I did find a link to an IFocusManager and IFocusManagerComponent, but neither seem to be available to me. Cheers.

A: 

How about using the click event to set focus to the textfield? Then you don't have to worry about whether or not the SimpleButton has a focusEnabled property.

Code should just be

stage.focus = myTextField;
David
Here's the problem... the SimpleButton is located in a separate class, and there is no guarantee that the TextField even exists. Furthermore, if the user is focused in some other (unknown) region, I don't want this button to steal focus from that, either - meaning I want the user to be able to use the SimpleButton without losing focus from WHEREVER they're working. They're over in La-La-Land (anywhere, really) doing something else, they use the button, it can't steal focus from where they WERE working to drop it into the TextField. Thanks for the idea, though.
Slobaum
Could you detect which object has the focus using stage.focus? You'd have to know which object had the focus before the button got it. For this, you might use the EnterFrame event, or a timer. In the EnterFrame handler, you set a var lastFocus = stage.focus. Then you do as I suggested above, since you'd know the last item to which focus was set. You'd need to make the scope of that var available throughout the app.
David
Hmm... that is a good question. It's not a perfect solution, and I wonder how it would play with the multiple-stage concept of AS3. I might give this a try, thanks @David. I would still prefer a more global solution... especially since this seems like a big gaping hole in the Adobe implementation. WTH??
Slobaum