AS3 escribió:
at clases::moverJugador$iinit()
He hecho muchos cambios en mi código, de hecho cuando tenia la animación con el código en el frame 1 en vez de un .as, lo podia importar sin problemas, pero se me hace mucho más conveniente hacer uso de clases, sólo que tengo este problema y no sé que pueda ser.
El código de mi archivo moverJugador.as es éste:
Código :
package clases {
import flash.events.*;
import flash.display.MovieClip;
public class moverJugador extends MovieClip {
//Configuracion del jugador
public static var velocidad:Number=3;
//Variables globales
public static var xDown:Boolean=false;
public static var yDown:Boolean=false;
public static var xDir:Number;
public static var yDir:Number;
public static var direccion:String;
//Constructor
public function moverJugador() {
//Eventos
this.stage.addEventListener(KeyboardEvent.KEY_DOWN,abajo);
this.stage.addEventListener(KeyboardEvent.KEY_UP,arriba);
this.stage.addEventListener(Event.ENTER_FRAME,quieto);
}
//Si no esta caminando, se detiene el movieClip, respetando la direccion
function quieto(ef:Event) {
if(xDown==false && yDown==false)
char.gotoAndPlay(direccion);
}
//Se ejecuta cuando esta presionada una tecla
function abajo(event:KeyboardEvent):void {
if(event.keyCode==40 || event.keyCode==38){ //Verifica que se presionen las flechas ARRIBA o ABAJO
yDown=true;
yDir=event.keyCode;
this.stage.addEventListener(Event.ENTER_FRAME, moveY);
}
if(event.keyCode==39 || event.keyCode==37){ //Verifica que se presionen las flechas IZQUIERDA o DERECHA
xDown=true;
xDir=event.keyCode;
this.stage.addEventListener(Event.ENTER_FRAME, moveX);
}
}
//Se ejecuta cuando se suelta una tecla
function arriba(event:KeyboardEvent):void {
if(event.keyCode==40 || event.keyCode==38){
yDown=false;
}
if(event.keyCode==39 || event.keyCode==37){
xDown=false;
}
}
//Se mueve verticalmente y detecta combinaciones de tecla para caminar esquineado
function moveY(evento:Event){
if(yDown==true){
if(yDir==38){
this.y-=velocidad;
if(xDown==true && xDir==37) {
if(direccion!="UL") { //Comprueba si ya esta caminando en esa direccion
char.gotoAndPlay("UL"); }//Up-left
direccion="UL"; }
else {
if(xDown==true && xDir==39) {
if(direccion!="UR") {
char.gotoAndPlay("UR"); } //Up-right
direccion="UR"; }
else {
if(direccion!="U") {
char.gotoAndPlay("U"); } //Up
direccion="U"; } } }
else if(yDir==40){
this.y+=velocidad;
if(xDown==true && xDir==37) {
if(direccion!="DL") {
char.gotoAndPlay("DL"); } //Down-left
direccion="DL"; }
else {
if(xDown==true && xDir==39) {
if(direccion!="DR") {
char.gotoAndPlay("DR"); } //Down-right
direccion="DR"; }
else {
if(direccion!="D") {
char.gotoAndPlay("D"); } //Down
direccion="D";
} }
}
}
}
//Se mueve horizontalmente, no necesita checar combinaciones de tecla
function moveX(evento:Event){
if(xDown==true){
if(xDir==37){
this.x-=velocidad;
if(yDown==false) {
if(direccion!="L") {
char.gotoAndPlay("L"); }
direccion="L"; }
}else if(xDir==39){
this.x+=velocidad;
if(yDown==false) {
if(direccion!="R") {
char.gotoAndPlay("R"); }
direccion="R"; }
}
}
}
}
}Éste archivo lo uso como Document Class en mi archivo jugador.swf. Y para importarlo en el otro archivo, main.swf, uso el siguiente código:
Código :
//Importamos clases
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.LoaderInfo;
import flash.utils.*;
//Creamos el objeto que contendrá al jugador
var char:Object;
//Creamos un contenedor para cargar el SWF del jugador
//Cuando se complete, se ira al metodo "cargado"
var contenedor:Loader=new Loader();
contenedor.contentLoaderInfo.addEventListener(Event.COMPLETE, cargado);
contenedor.load(new URLRequest("jugador.swf"));
stage.addChild(contenedor);
//Una vez cargado el archivo, se mete al objeto Char
function cargado(e:Event):void {
var loaderInfo:LoaderInfo = e.target as LoaderInfo;
addChild(e.target.content);
char=loaderInfo.content;
}Si corro esto, me marca el error que dije anteriormente, pero si no uso moverJugador.as en jugador.fla, lo carga sin problemas.
Ayudenme por favor
Bueno, espero haber sido lo suficientemente específico, saludos!
