Flash Tip: ComboBox Component Breaks Buttons
I’m posting this Flash problem more for my own future reference, but perhaps someone else will benefit.
Basically I’m generally wary of using the built-in Flash components, for whenever I get one working, I develop some bugs that have me wondering if I should have created something from scratch. My experience with the “ComboBox” component was no different.
The “ComboBox” is a drop down menu that you can fill with your own list. The user can pick an option and you get the data out.
After I got it working I realized it was breaking some buttons I had already created, but in a fairly subtle way. Say you have a button that the user can click on repeatedly, as in a number increment or in my case, a “next” button for an image gallery. The way it should work is the user can click on the button a ton of times in sequence without having to move the mouse.
But when combobox is activated, this behavior breaks. Meaning, in the example below, the button works as described above - until the user clicks on the ComboBox. Then the arrow buttons don’t work quite right. You have to move the mouse a little in order to reactive the button once you click on it.
Because the behavior changes after touching the ComboBox, I was pretty sure the component was the culprit. After doing some searching online, I found this fix at Jetfly (which in turn points to this fix at PhilterBlog ) where I learned of a “focus management” that the ComboBox takes a hold of, and is what causes the other buttons to change their behavior. You can return the focus to the buttons using something like:
next_btn.onPress = function(){
Selection.setFocus(this);
};
Great, this solves the button bug… but then Flash draws a yellow box around the buttons, for “keyboard focus”.
More searching revealed a property I never heard of called “_focusrect“, that you can use to turn off the yellow box:
next_btn.onPress = function(){
this._focusrect = false;
Selection.setFocus(this);
};
Unwanted behavior eliminated, and I learned stuff: 1) setFocus and focusrect, 2) reaffirmed my general annoyance with Flash components, and 3) as with most of my Flash problems, someone else has already encountered them and posted fixes online.
Previous Post:
Useful post here. It’s true not only for Flash but for many other things that your problem is already solved by someone else. Question is how good your are in finding that answer.
You da man! You saved me a lot of time. Thank!
Thank you so much! Been looking for a couple of hours; finally found the answer to my problem…so happy…