esto es una edición de la publicación original ahora que entiendo mejor el problema. ahora con código fuente!flash javascript events
En IE, si el cuerpo (o en otro div HTML tiene el foco), a continuación, haga clic en & pulsación de tecla flash al mismo tiempo , a continuación, suelte ... un evento keyup Nunca se dispara. No está activado en javascript o en flash. ¿Dónde está este evento clave?
Este es el orden de disparar caso se obtiene en su lugar:
- javascriptKeyEvent: bodyDn ** currentFocusedElement: cuerpo
- javascriptKeyEvent: docDn ** currentFocusedElement: cuerpo
- actionScriptEvent: activar ** currentFocusedElement: [object]
- actionScriptEvent: mouseDown ** currentFocusedElement: [object]
- actionScriptEvent: mouseUp ** currentFocusedElement: [object]
Los siguientes eventos de keydown y keyup son capturados por flash, pero esa keyUp inicial nunca se dispara .. en cualquier lugar. ¡Y necesito esa tecla!
lo que no funciona:
- comprobar si la clave es sin un oyente. Check if a key is down?
- wmode opaco o directo. Aunque, con opaco, es mucho más difícil de reproducir.
- empujando el foco a javascript lo antes posible para ver el evento. (Intentado esto con un oyente desenfoque en javascript y ajustar el enfoque cuando se activa AS3.)
- ni jQuery o prototipo capturan la falta keyup
- tanto estática como dinámica swfobject publicación
Aquí es el 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>
Este es el código 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);
}
}
}
}
No activar el evento de teclado en JavaScript me parece el comportamiento esperado. Los controles ActiveX consumen eventos y no los vuelven a propagar al documento que los contiene. Sin embargo, eso no explica por qué Flash no activa el evento correctamente, una pregunta interesante. Desafortunadamente, creo que las únicas personas que podrían responder la pregunta son el personal de Adobe :-) –