<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
applicationComplete="inicializacion();" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
/**
* Se ejecuta al crearse completamente la aplicacion para garantizar que el
* stage ya esté instanciado para agregarle los listener del teclado.
**/
private function inicializacion():void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN,tecladoHandler);
stage.addEventListener(KeyboardEvent.KEY_UP,restaurarHandler);
}
/**
* Handler para el evento de teclado KEY_DOWN
**/
private function tecladoHandler(event:KeyboardEvent):void
{
var glowFilter : GlowFilter = new GlowFilter();
if ((viewStackEjemplos.selectedChild == box1) &&
(event.keyCode == Keyboard.CONTROL))
{
textInput1.filters = [glowFilter]
button1.filters = [glowFilter];
linkButton1.filters = [glowFilter];
}
else
if ((viewStackEjemplos.selectedChild == box3) &&
(event.keyCode == 83) &&
(event.shiftKey))
{
textInput3.filters = [glowFilter]
button3.filters = [glowFilter];
linkButton3.filters = [glowFilter];
}
else
if ((viewStackEjemplos.selectedChild == box4) &&
(event.keyCode == 50) &&
(event.shiftKey))
{
var url:URLRequest = new URLRequest("javascript:window.close();");
navigateToURL(url,"_self");
}
}
/**
* Handler para el event MouseEvent.click
**/
private function clickHandler(event:MouseEvent):void
{
if ((viewStackEjemplos.selectedChild == box2) &&
(event.ctrlKey))
{
event.stopPropagation();
var glowFilter : GlowFilter = new GlowFilter();
event.target.filters = [glowFilter];
}
else
if (!(event.currentTarget is TextInput))
{
Alert.show(event.currentTarget.name + " despacho un evento comun.");
}
}
/**
* Handler para el evento de teclado KEY_UP. Quita el filtro a todos los componentes
* que pudieran tenerlo al quitar el dedo de la tecla.
**/
private function restaurarHandler(event:Event):void
{
if (button1 && linkButton1)
{
textInput1.filters = null;
button1.filters = null;
linkButton1.filters = null;
}
if (button2 && linkButton2)
{
textInput2.filters = null;
button2.filters = null;
linkButton2.filters = null;
}
if (button3 && linkButton3)
{
textInput3.filters = null;
button3.filters = null;
linkButton3.filters = null;
}
}
]]>
</mx:Script>
<mx:ButtonBar
id="buttonBar1"
dataProvider="{viewStackEjemplos}"/>
<mx:Box
x="10" y="30" width="734" height="114">
<mx:ViewStack
id="viewStackEjemplos"
x="0" y="0" width="100%" height="100%">
<mx:Box
id="box1"
width="100%" height="100%"
label="Evento presionando una tecla">
<mx:Label
text="Presiona la tecla Ctrl"/>
<mx:TextInput
id="textInput1"/>
<mx:Button
id="button1"
label="Boton 1"
click="clickHandler(event);"/>
<mx:LinkButton
id="linkButton1"
label="Enlace 1"
enabled="true"
click="clickHandler(event);"/>
</mx:Box>
<mx:Box
id="box2"
width="100%" height="100%"
label="Evento presionando una tecla + clic">
<mx:Label
text="Presiona la tecla Ctrl y haz clic sobre algun componente"/>
<mx:TextInput
id="textInput2"
click="clickHandler(event);"/>
<mx:Button
id="button2"
label="Boton 2"
click="clickHandler(event);"/>
<mx:LinkButton
id="linkButton2"
label="Enlace 2"
enabled="true"
click="clickHandler(event);"/>
</mx:Box>
<mx:Box
id="box3"
width="100%" height="100%"
label="Evento con combinacion de teclas">
<mx:Label
text="Presiona a la vez las teclas Shift + s"/>
<mx:TextInput
id="textInput3"/>
<mx:Button
id="button3"
label="Boton 3"
click="clickHandler(event);"/>
<mx:LinkButton
id="linkButton3"
label="Enlace 3"
enabled="true"
click="clickHandler(event);"/>
</mx:Box>
<mx:Box
id="box4"
width="100%" height="100%"
label="Evento con combinacion de teclas con JavaScript">
<mx:Label
text="Intenta cerrar el navegador presionando las teclas Shift + 2"/>
</mx:Box>
</mx:ViewStack>
</mx:Box>
</mx:Application>