[COLOR=Navy]Hi guys,
I had this ship working in the timeline and then took it into an .as file for a custom class and now it won’t work…
it is saved as Ship.as
[/COLOR]
public class Ship extends MovieClip
{
public function Ship():void
{
var gravityConstant:Number=0;
var uForce:Number=0;
var lForce:Number=0;
var rForce:Number=0;
this.addEventListener(KeyboardEvent.KEY_DOWN,moveShip);
this.addEventListener(Event.ENTER_FRAME, addForceVectors)
function addForceVectors(event:Event)
{
this.x +=rForce-lForce;
this.y +=gravityConstant -uForce;
gravityConstant +=.1;
if (gravityConstant>15)
{
gravityConstant=15;
}
if (uForce>0)
{
uForce=(uForce-(uForce*.25));//diminishThrustMomentum
}
if(uForce>gravityConstant)
{
gravityConstant=0;//lets thrust momentum occur
}
trace(this.gravityConstant)
trace(this.uForce)
}
function moveShip(evt:KeyboardEvent):void
{
switch (evt.keyCode)
{
case Keyboard.UP:
uForce +=5;
burn();
break;
case Keyboard.LEFT:
lForce +=1;
burn();
break;
case Keyboard.RIGHT:
rForce+=1;
burn();
break;
default:
trace("keyCode:",evt.keyCode);
}
}
function burn():void
{
trace("burn")
}
}
}
}
[COLOR=Navy]the traces are coming up undefined with no errors
the timeline frame 1 actions code is…[/COLOR]
var ship_mc:Ship= new Ship;
addChild (ship_mc);