使用javascript禁用AS2嵌入的FF按键
对于AS2,我需要允许用户按“Alt+N”进入下一页,但问题是,在Windows中,每当按下Alt时,就会将焦点从flash嵌入中移开,而keylistener永远不会接收到它使用javascript禁用AS2嵌入的FF按键,javascript,firefox,actionscript-2,keyboard-events,Javascript,Firefox,Actionscript 2,Keyboard Events,对于AS2,我需要允许用户按“Alt+N”进入下一页,但问题是,在Windows中,每当按下Alt时,就会将焦点从flash嵌入中移开,而keylistener永远不会接收到它 研究该怎么做,似乎解决方案是使用Javascript禁用Firefox(需要在其中运行的浏览器)中ALT键的默认操作。我不确定这是否是正确的路径,也不确定如何做到这一点;大概是这样的: function keyCodeReceptor( code ){ switch ( code ) { case 67:
研究该怎么做,似乎解决方案是使用Javascript禁用Firefox(需要在其中运行的浏览器)中ALT键的默认操作。我不确定这是否是正确的路径,也不确定如何做到这一点;大概是这样的:
function keyCodeReceptor( code ){
switch ( code ) {
case 67:
// go to the next page
break;
// add any other keys you need to bind to "Alt+key" combination
default:
break;
}
}
flash.external.ExternalInterface.addCallback( 'doKey', null, keyCodeReceptor );
然后,在要嵌入对象的HTML中需要类似以下内容:
(function(){
// Use the name or index of your embed here
var flash = document.embeds[0];
window.addEventListener( 'keydown', function( event ){
if( event.altKey && event.keyCode == 67 ){
event.preventDefault();
event.preventCapture();
event.preventBubble();
flash.doKey(event.keyCode);
}
});
})();
另外,确保嵌入的allowScriptAccess
属性设置为“始终”
我只测试了Firefox(最新版本,Mac和Windows),所以我根本不知道它是否适用于其他浏览器。希望这有帮助 嗯,在flash程序中需要一个外部接口;大概是这样的:
function keyCodeReceptor( code ){
switch ( code ) {
case 67:
// go to the next page
break;
// add any other keys you need to bind to "Alt+key" combination
default:
break;
}
}
flash.external.ExternalInterface.addCallback( 'doKey', null, keyCodeReceptor );
然后,在要嵌入对象的HTML中需要类似以下内容:
(function(){
// Use the name or index of your embed here
var flash = document.embeds[0];
window.addEventListener( 'keydown', function( event ){
if( event.altKey && event.keyCode == 67 ){
event.preventDefault();
event.preventCapture();
event.preventBubble();
flash.doKey(event.keyCode);
}
});
})();
另外,确保嵌入的allowScriptAccess
属性设置为“始终”
我只测试了Firefox(最新版本,Mac和Windows),所以我根本不知道它是否适用于其他浏览器。希望这有帮助