The Flash Button One-Click Wonder
I recently ran into a really puzzling problem. I was creating an administrative interface in Flash, which included a few form elements (flash components) and some custom buttons. One of the buttons was a toggle switch, with a funny behavior! I could only click the button once! Subsequent clicks were ignored until I moved the cursor. Just a single pixel would suffice, but for some reason it needed to reactive the onrollover event for the button.
I ran into a helpful thread in the Flashkit archive. Here’s the gist of the problem, and my recommended solution (it’s a little different than the initial one posted on Flashkit):
- The problem: a combobox on the same page was stealing the focus away from the button after the dropdown was activated
- The original solution: use “setFocus” to return focus to the button, when the button is clicked
- The preferred solution: use “setFocus” to unset the focus completely whenever the dropdown is activated
For the original solution, here is some sample code that you would add to the end of your button “onPress” event:
Selection.setFocus(this);
For the preferred solution, here is the sample code that you would add to the code that processes the combobox selection (the onChange event):
Selection.setFocus(null);
The reason why I like the second method better is because the first method is a solution to the symptom. The second method is a solution to the problem. If you had multiple buttons with this problem, you would need to add the first code to each button. Or you could add the code once to the problematic combobox and you’re done.
