1°Nave.as, Línea 22 1046: No se encontró el tipo o no es una constante en tiempo de compilación: Event.
2°Nave.as, Línea 168 1046: No se encontró el tipo o no es una constante en tiempo de compilación: KeyboardEvent.
3°Nave.as, Línea 205 1046: No se encontró el tipo o no es una constante en tiempo de compilación: KeyboardEvent.
Este es mi codigo bien descrito con sus variables y como podran ver el fin es muy simple, hacer que el objeto principal gire y se mueva solo hacia adelante. Es por eso que necesito del evento de movimiento por medio del teclado:
Código ActionScript :
package
{
public class Nave
{
// Variables: cu= cuadrado de golpe 1, cu1= cuadrado de golpe 2, cu2= cuadrado de golpe 3, cu3= cuadrado de golpe 4
// Variables: nave= El jugador de la nave, vn= velocidad de la nave, vr= velocidad de rotacion de la nave,
// Variables: tg= angulo de rotacion de la nave
cu.x = nave.x;
cu.y = nave.y;
cu2.x = nave.x;
cu2.y = nave.y;
cu1.x = nave.x;
cu1.y = nave.y;
cu3.x = nave.x;
cu3.y = nave.y;
public var tg:Number = nave.rotation;
public var vn:Number;
public var vr:Number;
public var up:Boolean = false;
public var down:Boolean = false;
public var left:Boolean = false;
public var right:Boolean = false;
public function MovDir(event:Event)
{
if (up)
{
tg = nave.rotation;
if (nave.rotation == 0)
{
nave.y -= vn;
cu.y -= vn;
cu1.y -= vn;
cu2.y -= vn;
cu3.y -= vn;
}
if (nave.rotation == 180)
{
nave.y += vn;
cu.y += vn;
cu1.y += vn;
cu2.y += vn;
cu3.y += vn;
}
if (nave.rotation == -180)
{
nave.y += vn;
cu.y += vn;
cu1.y += vn;
cu2.y += vn;
cu3.y += vn;
}
if (nave.rotation == -90)
{
nave.x -= vn;
cu.x -= vn;
cu1.x -= vn;
cu2.x -= vn;
cu3.x -= vn;
}
if (nave.rotation == 90)
{
nave.x += vn;
cu.x += vn;
cu1.x += vn;
cu2.x += vn;
cu3.x += vn;
}
if (tg>0 && tg<90)
{
for (var i:Number = 1; i <= 90; i++)
{
if (i==tg)
{
nave.y -= vn - (i * (vn / 90));
nave.x += (i * (vn / 90));
cu.y -= vn - (i * (vn / 90));
cu.x += (i * (vn / 90));
cu1.y -= vn - (i * (vn / 90));
cu1.x += (i * (vn / 90));
cu2.y -= vn - (i * (vn / 90));
cu2.x += (i * (vn / 90));
cu3.y -= vn - (i * (vn / 90));
cu3.x += (i * (vn / 90));
i = 89;
}
}
}
if (tg>90 && tg<180)
{
for (var i2:Number = 91; i2 <= 180; i2++)
{
if (i2==tg)
{
nave.y += ((i2 - 90) * (vn / 90));
nave.x -= - vn + ((i2 - 90) * (vn / 90));
cu.y += ((i2 - 90) * (vn / 90));
cu.x -= - vn + ((i2 - 90) * (vn / 90));
cu1.y += ((i2 - 90) * (vn / 90));
cu1.x -= - vn + ((i2 - 90) * (vn / 90));
cu2.y += ((i2 - 90) * (vn / 90));
cu2.x -= - vn + ((i2 - 90) * (vn / 90));
cu3.y += ((i2 - 90) * (vn / 90));
cu3.x -= - vn + ((i2 - 90) * (vn / 90));
i2 = 179;
}
}
}
if (tg>-90 && tg<0)
{
for (var i3:Number = -1; i3 >=-90; i3--)
{
if (i3==tg)
{
nave.y -= vn + (i3 * (vn / 90));
nave.x += (i3 * (vn / 90));
cu.y -= vn + (i3 * (vn / 90));
cu.x += (i3 * (vn / 90));
cu1.y -= vn + (i3 * (vn / 90));
cu1.x += (i3 * (vn / 90));
cu2.y -= vn + (i3 * (vn / 90));
cu2.x += (i3 * (vn / 90));
cu3.y -= vn + (i3 * (vn / 90));
cu3.x += (i3 * (vn / 90));
i3 = -89;
}
}
}
if (tg>-180 && tg<-90)
{
for (var i4:Number = -91; i4 >= -180; i4--)
{
if (i4==tg)
{
nave.y -= ((i4 + 90) * (vn / 90));
nave.x += - vn + (((i4 * -1) - 90) * (vn / 90));
cu.y -= ((i4 + 90) * (vn / 90));
cu.x += - vn + (((i4 * -1) - 90) * (vn / 90));
cu1.y -= ((i4 + 90) * (vn / 90));
cu1.x += - vn + (((i4 * -1) - 90) * (vn / 90));
cu2.y -= ((i4 + 90) * (vn / 90));
cu2.x += - vn + (((i4 * -1) - 90) * (vn / 90));
cu3.y -= ((i4 + 90) * (vn / 90));
cu3.x += - vn + (((i4 * -1) - 90) * (vn / 90));
i2 = 179;
}
}
}
trace("Angulo:" + tg);
}
if (left)
{
nave.rotation -= vr;
cu.rotation -= vr;
cu1.rotation -= vr;
cu2.rotation -= vr;
cu3.rotation -= vr;
}
if (right)
{
nave.rotation += vr;
cu.rotation += vr;
cu1.rotation += vr;
cu2.rotation += vr;
cu3.rotation += vr;
}
}
public function TPress(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP :
{
up = true;
break;
};
case Keyboard.LEFT :
{
left = true;
break;
};
case Keyboard.RIGHT :
{
right = true;
break;
}
}
};
public function TUPress(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP :
{
up = false;
break;
};
case Keyboard.LEFT :
{
left = false;
break;
};
case Keyboard.RIGHT :
{
right = false;
break;
}
}
};
nave.addEventListener(Event.ENTER_FRAME, MovDir);
stage.addEventListener(KeyboardEvent.KEY_DOWN, TPress);
stage.addEventListener(KeyboardEvent.KEY_UP, TUPress);
public function Nave()
{
// constructor code
}
}
}Grasias por leer y espero y me puedan ayudar
Saludos
