Comunidad de diseño web y desarrollo en internet online

Problema con movimiento mediante teclas.

Citar            
MensajeEscrito el 01 May 2012 06:52 pm
Hola, tengo en flash, dos escenas. la primera es un menú simple y dentro de ese menú, hay un botón para enviar a la siguiente.

La siguiente escena es un jueguito accionado por teclas, el cual, al oprimir (A, S, D y F) se reproducen las acciones.
Mi problema es que al cambiar de la escena 1 a la escena 2, las teclas no se activan sin antes darle click en el escenario.

¿Hay alguna forma de que las teclas se activen una vez entre a la escena sin necesidad de hacer click?


Agradezco su ayuda.
Buen día.

Por dmperez777

10 de clabLevel



 

chrome
Citar            
MensajeEscrito el 02 May 2012 01:44 am
Con qué código insertaste los listeners?

Por nasho

Claber

908 de clabLevel

1 tutorial

Genero:Masculino  

Web Developer

chrome
Citar            
MensajeEscrito el 02 May 2012 02:43 am

nasho escribió:

Con qué código insertaste los listeners?


Código :

import flash.events.MouseEvent;

var contador:Number=0;
pul1.visible = false;
pul2.visible = false;
pul3.visible = false;
pul4.visible = false;
mal.visible= false;
cta.visible= false;
tra.visible= false;
sda.visible= false;
pra.visible= false;
function frente(event:MouseEvent):void
{
   mal.addChild(event.currentTarget as DisplayObject);
   mov.addChild(event.currentTarget as DisplayObject);
   mov2.addChild(event.currentTarget as DisplayObject);
   mov3.addChild(event.currentTarget as DisplayObject);
   mov4.addChild(event.currentTarget as DisplayObject);
   
}

stage.addEventListener(KeyboardEvent.KEY_DOWN, pin);
function pin(event:KeyboardEvent):void{
      if(event.keyCode == Keyboard.A){
         if (mov.y >=275 && mov.y <=375){
         pul1.visible = true;
         pul1.play();
         contador += 1;
         cta.visible= true;
         t.text = contador.toString();
         tra.visible= false;
         sda.visible= false;
         pra.visible= false;
      }else{
         mal.visible= true;
         mal.x = 40;
         mal.y = 280;
         mal.play();
         contador -= 1;
         t.text = contador.toString();
      }
      }
      if(event.keyCode == Keyboard.S){
         if (mov2.y >=275 && mov2.y <=375){
         pul2.visible = true;
         pul2.play();
         contador += 1;
         tra.visible= true;
         cta.visible= false;
sda.visible= false;
pra.visible= false;
         t.text = contador.toString();
      }else{
         mal.visible= true;
         mal.x = 107;
         mal.y = 280;
         mal.play();
         contador -= 1;
         t.text = contador.toString();
      }
      }
      if(event.keyCode == Keyboard.D){
         if (mov3.y >=275 && mov3.y <=375){
         pul3.visible = true;
         pul3.play();
         contador += 1;
         sda.visible= true;
         tra.visible= false;
cta.visible= false;
pra.visible= false;
         t.text = contador.toString();
      }else{
         mal.visible= true;
         mal.x = 178;
         mal.y = 280;
         mal.play();
         contador -= 1;
         t.text = contador.toString();
      }
      }
      if(event.keyCode == Keyboard.F){
         if (mov4.y >=275 && mov4.y <=375){
         pul4.visible = true;
         pul4.play();
         contador += 1;
         pra.visible= true;
         tra.visible= false;
sda.visible= false;
cta.visible= false;
         t.text = contador.toString();
      }else{
         mal.visible= true;
         mal.x = 248;
         mal.y = 280;
         mal.play();
         contador -= 1;
         t.text = contador.toString();
      }
      }
}

Por dmperez777

10 de clabLevel



 

chrome
Citar            
MensajeEscrito el 02 May 2012 06:05 pm
proba agregando

Código ActionScript :

stage.focus = this;



Saludos


eXe

Por exekiel21

Claber

164 de clabLevel



Genero:Masculino  

programador

chrome
Citar            
MensajeEscrito el 02 May 2012 10:53 pm

exekiel21 escribió:

proba agregando

Código ActionScript :

stage.focus = this;



Saludos


eXe


MIL GRACIAS.
A LA PERFECCIÓN.

Por dmperez777

10 de clabLevel



 

chrome

 

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