flashactionscript-2flash-cs5.5

Prevent focus change with arrow keys in Flash AS2 event handler?


I've inherited some old Flash media at work. Requirements put forth by a client, as well as a time constraint, dictate that we cannot use anything higher than the set publish settings for Flash Player 9 and ActionScript 2.0.

I've got a component that acts as a timer bar and I'm trying to make it rewind or fast forward the movie 5 seconds when the left or right arrow key is pressed, for accessibility. However, the left and right arrow keys will move keyboard focus to the next or previous tabbable item after the keydown handler fires.

How can I stop this? With AS3 or JavaScript I'd be able to call Event.preventDefault() which I'm pretty sure would fix the problem, but I don't seem to have that luxury in AS2.


Solution

  • What I ended up doing to solve this problem, at least for now, was to set the seek bar's _focusRect property to false, and then added onKillFocus and onSetFocus handlers to remove and add a glow filter to it that looked like the yellow outline. _focusRect = false achieves what I needed because it stops the arrow keys from shifting focus, but I can tab in and out of the object with the Tab key still. From the documentation for MovieClip._focusRect:

    If the _focusrect property is set to false, keyboard navigation for that movie clip is limited to the Tab key. All other keys, including the Enter and arrow keys, are ignored. To restore full keyboard navigation, you must set _focusrect to true.

    Only thing is, in doing this you need to make sure to add your own handlers for interactions that are probably taken for granted, like hitting Enter or Space.