这是对原始帖子的编辑,现在我更好地理解了这个问题。 现在有源代码!
在 IE 中,如果 body(或另一个 html div 具有焦点),那么您同时按下并单击 flash ,然后释放...永远不会触发 keyup 事件。它不会在 javascript 或 flash 中触发。这个keyup事件在哪里?
这是您获得的事件触发顺序:
- javascriptKeyEvent:bodyDn ** currentFocusedElement:body
- javascriptKeyEvent: docDn ** currentFocusedElement: 正文
- actionScriptEvent : 激活 ** currentFocusedElement: [object]
- actionScriptEvent : mouseDown ** currentFocusedElement: [object]
- actionScriptEvent : mouseUp ** currentFocusedElement: [object]
随后的 keydown 和 keyup 事件由 flash 捕获,但初始 keyUp 永远不会在任何地方触发。我需要那个键位!
什么不起作用:
- 检查密钥是否在没有侦听器的情况下启动。 检查一个键是否已关闭?
- wmode 不透明或直接。虽然,使用不透明,复制要困难得多。
- 尽快将焦点推回 javascript 以赶上 up 事件。(在 javascript 中使用模糊侦听器尝试此操作,并在激活 as3 时设置焦点。)
- jquery 或原型都没有捕获丢失的 keyup
- 静态和动态 swfobject 发布
这是html/javascript:
<html>
<head>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
<script>
function ic( evt )
{ Event.observe( $("f1"), 'keyup', onKeyHandler.bindAsEventListener( this, "f1Up" ) );
Event.observe( $("f2"), 'keyup', onKeyHandler.bindAsEventListener( this, "f2Up" ) );
Event.observe( document, 'keyup', onKeyHandler.bindAsEventListener( this, "docUp" ) );
Event.observe( $("body"), 'keyup', onKeyHandler.bindAsEventListener( this, "bodyUp" ) );
Event.observe( window, 'keyup', onKeyHandler.bindAsEventListener( this, "windowUp" ) );
Event.observe( $("f1"), 'keydown', onKeyHandler.bindAsEventListener( this, "f1Dn" ) );
Event.observe( $("f2"), 'keydown', onKeyHandler.bindAsEventListener( this, "f2Dn" ) );
Event.observe( document, 'keydown', onKeyHandler.bindAsEventListener( this, "docDn" ) );
Event.observe( $("body"), 'keydown', onKeyHandler.bindAsEventListener( this, "bodyDn" ) );
Event.observe( window, 'keydown', onKeyHandler.bindAsEventListener( this, "windowDn" ) );
Event.observe( "clr", "mousedown", clearHandler.bindAsEventListener( this ) );
swfobject.embedSWF( "tmp.swf",
"f2",
"100%",
"20px",
"9.0.0.0", null, {}, {}, {} );
}
function clearHandler( evt )
{ clear( );
}
function clear( )
{ $("log").innerHTML = "";
}
function onKeyHandler( evt, dn )
{ logIt( "javascriptKeyEvent:"+dn );
}
function AS2JS( wha )
{ logIt( "actionScriptEvent::" + wha );
}
function logIt( k )
{
var id = document.activeElement;
if (id.identify)
{ id = id.identify();
}
$("log").innerHTML = k + " ** focuedElement: " + id + "<br>" + $("log").innerHTML;
}
Event.observe( window, 'load', ic.bindAsEventListener(this) );
</script>
</head>
<body id="body">
<div id="f1"><div id="f2" style="width:100%;height:20px; position:absolute; bottom:0px;"></div></div>
<div id="clr" style="color:blue;">clear</div>
<div id="log" style="overflow:auto;height:200px;width:500px;"></div>
</body>
</html>
这是as3代码:
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.external.ExternalInterface;
public class tmpa extends Sprite
{
public function tmpa( ):void
{
extInt("flashInit");
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDnCb, false, 0, true );
stage.addEventListener( KeyboardEvent.KEY_UP, keyUpCb, false, 0, true );
stage.addEventListener( MouseEvent.MOUSE_DOWN, mDownCb, false, 0, true );
stage.addEventListener( MouseEvent.MOUSE_UP, mUpCb, false, 0, true );
addEventListener( Event.ACTIVATE, activateCb, false, 0, true );
addEventListener( Event.DEACTIVATE, dectivateCb, false, 0, true );
}
private function activateCb( evt:Event ):void
{ extInt("activate");
}
private function dectivateCb( evt:Event ):void
{ extInt("deactivate");
}
private function mDownCb( evt:MouseEvent ):void
{ extInt("mouseDown");
}
private function mUpCb( evt:MouseEvent ):void
{ extInt("mouseUp");
}
private function keyDnCb( evt:KeyboardEvent ):void
{ extInt( "keyDn" );
}
private function keyUpCb( evt:KeyboardEvent ):void
{ extInt( "keyUp" );
}
private function extInt( wha:String ):void
{ try
{ ExternalInterface.call( "AS2JS", wha );
}
catch (ex:Error)
{ trace('ex: ' + ex);
}
}
}
}