Created
July 2, 2014 16:37
-
-
Save itsDanOades/f0e11196e01f6bc340ab to your computer and use it in GitHub Desktop.
Using an External Interface callback to control tabbing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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