Enable Page Reloads Even When Flash Has Stolen Keyboard Focus

Sick of having to click elsewhere to unfocus your Flash movie in order to reload (CTRL+R, F5) the page? Splendid. Just listen for the same keyboard events in ActionScript and call the JavaScript yourself.

import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.external.ExternalInterface;

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);

protected function onKeyDown(e:KeyboardEvent):void {
    var ctrlR:Boolean = !e.shiftKey && !e.altKey && e.ctrlKey && e.keyCode == Keyboard.R;
    if ( ctrlR || e.keyCode == Keyboard.F5 ){
        ExternalInterface.call('window.location.reload');
    }
}

About this entry


Good Reads