the code is to turn on the fire(from the thrusters of course:cyborg:) when the up key is pushed and turn it off when it’s up. And it works except that each time the fire is further and further away from the ship. Every time i add the fire child it’s set to the x and y of the ship(plus and minus cause i don’t have the reg point set right) . Also even though everything is at least semi functional i get this error while its all running
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
here is le code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
/**
* ...
* @author RwM
*/
public class Main extends MovieClip
{
var ship:Ship=new Ship ;
var fire:Fire=new Fire;
var vr:Number = 0;
var thrust:Number = 0;
var vx:Number = 0;
var vy:Number = 0;
var gravity:Number=.01;
public function Main()
{
addChild(ship);
ship.x = stage.width / 2;
ship.y = stage.height / 2;
/*ship.addChild(fire);
fire.x=ship.x-70;
fire.y=ship.y-65;*/
addEventListener(Event.ENTER_FRAME, eenterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, kkeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, kkeyUp);
}
public function kkeyDown(event:KeyboardEvent):void
{
var key:uint = event.keyCode;
switch(key)
{
case Keyboard.LEFT:
vr = -5;
break;
case Keyboard.RIGHT:
vr = 5;
break;
case Keyboard.UP:
thrust = 0.2;
ship.addChild(fire);
fire.x=ship.x-70;
fire.y=ship.y-65;
break;
default:
break;
}
}
function kkeyUp(event:KeyboardEvent):void
{
vr =0;
thrust=0;
ship.removeChild(fire);
}
function eenterFrame(event2:Event):void
{
ship.rotation +=vr;
var angle:Number=ship.rotation*Math.PI/180;
var ay:Number=Math.cos(angle)*thrust; //adjacent/hypot
var ax:Number=Math.sin(angle)*thrust;//opposite/hypot
vx +=ax;
vy +=ay ;
vy -=gravity;
ship.y -=vy;
ship.x +=vx;
}
can anybody square me away on this?