Skip to content

Instantly share code, notes, and snippets.

@itsDanOades
Created July 2, 2014 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsDanOades/f0e11196e01f6bc340ab to your computer and use it in GitHub Desktop.
Save itsDanOades/f0e11196e01f6bc340ab to your computer and use it in GitHub Desktop.
Using an External Interface callback to control tabbing
//JavaScript code
//Create a HTML anchor point beforeFlash
var beforeFlash = $('<div id="beforeFlash"><a href="http://www.bbc.co.uk">Link 1</a></div>');
//Add focus listener to beforeFlash to manually override tab controls when using tabs through page
beforeFlash.keydown(function (event) {
//Override tab controls to manually pass focus to Flash
var keyCode = event.keyCode || event.which;
//If we are tabbing forward
if (keyCode === 9 && !event.shiftKey) {
if (event.preventDefault) {
event.preventDefault();
}
event.returnValue = false;
setTimeout(function () {
beforeFlash.blur();
//Call focusOnFirst, a method exposed by our Flash movie ExternalInterface
flashMovieInstance.focusOnFirst();
flashMovie.tabIndex = 0;
flashMovieInstance.focus();
}, 200); //Add delay to prevent flash from receiving the tab key event
}
});
}
//Flash Code
//Add an external interface callback for JS to invoke
if(ExternalInterface.available)
{
ExternalInterface.addCallback('focusOnFlash', focusOnFlash);
}
//Manually set stage focus in the Flash movie to the first element in your Flash tab index when invoked by JS
public function focusOnFlash() : void
{
stage.focus = theFirstDisplayObjectInMyTabIndex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment