Comunidad de diseño web y desarrollo en internet online

Loca de remate con un problema de key event listener !!

Citar            
MensajeEscrito el 09 Mar 2008 07:41 pm
Hola a todos, soy nueva en el barrio !!
Os cuento lo k quiero...
Intento capturar una secuencia de teclas, normalmente se puede capturar los números del 1 al 9 pq son teclas independientes, pero ¿qué pasa si queremos capturar el 11?
Con este código, si eres rápido tecleando, puedes hacerlo, pues si mantienes pulsada la tecla DOWN, te permite guardar en un array dos valores (Sólo 2).
El problema: Tener pulsada la tecla DOWN también envía valores al Array() por lo que si la mantienes pulsada y tardas en introducir los otros dos, el Array se rellena y devuelve el valor 0.
¿Cómo hacer que los valores arrojados por DOWN no afecten al array?
He probado mil maneras:
Desde decirle a la orden de push.array k sólo acepte valores ascii comprendidos entre 48 y 57 hasta decirle que no acepte ni cero ni undefined, pero no me obedece...
AYUDADME PLEASE :crap:

Código :

_global.knumbers = new Array();
_global.knumber = 0;
_global.thenum = 0;
_global.thenum1 = 0;
_global.thenum2 = 0;
var listKey1:Object = new Object();
listKey1.onKeyDown = function () {
if (Key.isDown(Key.DOWN)) {
var listKey:Object = new Object();
listKey.onKeyDown = function () {
   _global.knumbers.push(Key.getAscii());
if (_global.knumbers.length == 2){
if (_global.knumbers[0] == 48){
_global.thenum = 0;
   }
if (_global.knumbers[0] == 49){
_global.thenum = 1;
   }
if (_global.knumbers[0] == 50){
_global.thenum = 2;
   }
if (_global.knumbers[0] == 51){
_global.thenum = 3;
   }
if (_global.knumbers[0] == 52){
_global.thenum = 4;
   }
if (_global.knumbers[0] == 53){
_global.thenum = 5;
   }
if (_global.knumbers[0] == 54){
_global.thenum = 6;
   }
if (_global.knumbers[0] == 55){
_global.thenum = 7;
   }
if (_global.knumbers[0] == 56){
_global.thenum = 8;
   }
if (_global.knumbers[0] == 57){
_global.thenum = 9;
   }
if (_global.knumbers[1] == 48){
_global.thenum1 = 0;
   }
if (_global.knumbers[1] == 49){
_global.thenum1 = 1;
   }
if (_global.knumbers[1] == 50){
_global.thenum1 = 2;
   }
if (_global.knumbers[1] == 51){
_global.thenum1 = 3;
   }
if (_global.knumbers[1] == 52){
_global.thenum1 = 4;
   }
if (_global.knumbers[1] == 53){
_global.thenum1 = 5;
   }
if (_global.knumbers[1] == 54){
_global.thenum1 = 6;
   }
if (_global.knumbers[1] == 55){
_global.thenum1 = 7;
   }
if (_global.knumbers[1] == 56){
_global.thenum1 = 8;
   }
if (_global.knumbers[1] == 57){
_global.thenum1 = 9;
   }
_global.thenum2 = ((_global.thenum)*10)+_global.thenum1;
_root.writeit.text = thenum2;
   }
}
Key.addListener(listKey);
   }
}
Key.addListener(listKey1);

Por PrincesaLeya

39 de clabLevel



Genero:Femenino  

msie7
Citar            
MensajeEscrito el 09 Mar 2008 10:22 pm

Por mcapu

181 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 10 Mar 2008 10:39 pm
Gracias mcapu, al fin lo resolví !!

Por PrincesaLeya

39 de clabLevel



Genero:Femenino  

msie7

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.