1 package { 2 3 import flash.display.MovieClip; 4 5 6 public class main extends MovieClip { 7 8 public var pelota1:pelota; 9 10 public function main() { 11 pelota1=new pelota(); 12 pelota1.cambioXY(); 13 //pelota1.escuchador(); 14 15 addChild(pelota1); 16 pelota1.escuchador2(); 17 } 18 } 19 20 }
1 package { 2 3 import flash.display.MovieClip; 4 import flash.events.*; 5 import flash.ui.*; 6 7 8 public class pelota extends MovieClip { 9 10 11 public function pelota(){ 12 x=100; 13 y=100; 14 trace("hola soy la pelota"); 15 } 16 17 public function cambioXY(){ 18 x=300; 19 y=300; 20 } 21 22 public function mensaje(b:Event){ 23 trace("hola"); 24 } 25 26 public function escuchador(){ 27 addEventListener(Event.ENTER_FRAME,mensaje); 28 } 29 30 31 public function mover(e:KeyboardEvent){ 32 33 //trace("mover"); 34 switch(e.keyCode){ 35 case 37: 36 x=x-2; 37 trace("hola1"); 38 if (e.keyCode==38){ 39 trace("hola2"); 40 y=y-2; 41 x=x-2; 42 } 43 break; 44 case 38: 45 y=y-2; 46 break; 47 case 39: 48 x=x+2; 49 break; 50 case 40: 51 y=y+2; 52 break; 53 } 54 /*if(e.keyCode == Keyboard.){ 55 trace("hola"); 56 y=y-2; 57 x=x-2; 58 }*/ 59 } 60 61 public function escuchador2(){ 62 stage.addEventListener(KeyboardEvent.KEY_DOWN,mover); 63 } 64 65 66 } 67 68 }
No hay comentarios:
Publicar un comentario