He logrado mover un MC utilizando una clase, pero al mover no se ve fluido, me la pase días dándole vuelta y no logro solucionarlo, les paso el código.
Código ActionScript :
package
{
import flash.display.*;
import flash.events.*;
public class Personaje_jugador extends MovieClip
{
public function Personaje_jugador()
{
addEventListener(Event.ADDED_TO_STAGE, stage1);
addEventListener( Event.ENTER_FRAME, mover );
}
function stage1(e:Event):void
{
stage.addEventListener( KeyboardEvent.KEY_DOWN, presionartecla);
stage.addEventListener( KeyboardEvent.KEY_UP, soltartecla);
}
public var velocidad = 10;
private var arriba = false;
private var abajo = false;
private var izquierda = false;
private var derecha = false;
private function presionartecla(tecla:KeyboardEvent)
{
switch (tecla.keyCode)
{
case 37 :
izquierda = true;
break;
case 38 :
arriba = true;
break;
case 39 :
derecha = true;
break;
case 40 :
abajo = true;
}
}
private function soltartecla(tecla:KeyboardEvent)
{
switch (tecla.keyCode)
{
case 37 :
izquierda = false;
break;
case 38 :
arriba = false;
break;
case 39 :
derecha = false;
break;
case 40 :
abajo = false;
}
}
private function moverpersonaje()
{
if (izquierda)
{
x -= velocidad;
}
else if (derecha)
{
x += velocidad;
}
if (arriba)
{
y -= velocidad;
}
else if (abajo)
{
y += velocidad;
}
}
private function mover(e:Event):void
{
moverpersonaje();
}
}
} 