Copy link to clipboard
Copied
so i am a highschool student and i am working on a project in game design and so im working on it then this 1009 asshole comes up and i have been working on getting rid of this for a few days with no luck or only bad luck. so i asked my teacher he couldnt fix it and after about 10 minutes basically he said i cant fix it so go to the forums and i had already. so in the code it says it is line 103 which i will mark with a this is line 103 in all caps. there is an a4 and there is a ship.
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.display.DisplayObject;
//go to a1, it needs to be fixed
stop();
var speedVert:Number=0;
var speedHoriz:Number=0;
instr_txt.alpha-=2;
ship.x=275;
ship.y=200;
var angle:Number = Math.atan2(ship.y - this.y, ship.x - this.x);
var xstep:Number = Math.cos(angle) * this.speed;
var ystep:Number = Math.sin(angle) * this.speed;
function q1(evt:MouseEvent):void
{
gotoAndStop(107);
}
a1.addEventListener(MouseEvent.CLICK, q1);
function moveShip(event:KeyboardEvent):void{
if(event.keyCode==38){
ship.y-=3;
}
if(event.keyCode==40){
ship.y+=3;
}
}
function rotateShip(event:KeyboardEvent):void{
if(event.keyCode==39){
ship.rotation+=5;
}
if(event.keyCode==37){
ship.rotation-=5;
}
}
//function shipInit(event:KeyboardEvent):void{
//attachMovie("ship", "ship_mc", 2);
//ship._x = RIGHT/2;
//ship._y = BOTTOM/2;
//ship.VELX = 0;
//ship.VELY = 0;
//ship.onEnterFrame = control;
//ROTATE = 0;
//THRUST = 0;
//}
stage.addEventListener(KeyboardEvent.KEY_DOWN, moveShip);
stage.addEventListener(KeyboardEvent.KEY_DOWN, rotateShip);
function loop(evt:Event):void
{
//rocks below
a1.rotation+=12;
a2.rotation+=15;
a3.rotation+=5;
a4.rotation+=10;
a5.rotation+=11;
if(a1.y<=-50)
{
a1.y=435;
}
if(a2.y<=-50)
{
a2.y=445;
}
if(a3.x<=-55)
{
a3.x=614;
}
if(a4.x>=614)
{
a4.x=-30;
}
if(a5.y>=450)
{
a5.y=-30;
}
a1.y-=1;
a2.y-=2;
a3.x-=3;
a4.x+=2;
a5.y+=1;
}
a4.gotoAndStop("liquid");
stage.addEventListener(Event.ENTER_FRAME, loop);
ship.addEventListener(Event.ENTER_FRAME, stage2);
function stage2(evt:Event):void
{
if (ship.hitTestObject(a4)){ (THIS IS LINE 103)
gotoAndStop(128);
//stage.removeEventListener(KeyboardEvent.KEY_DOWN, moveShip);
//stage.removeEventListener(KeyboardEvent.KEY_DOWN, rotateShip);
stage.removeEventListener(Event.ENTER_FRAME, stage2);
stage.removeEventListener(Event.ENTER_FRAME, loop);
}
}
/*function resetA (evt:Event):void{
if (ship.hitTestObject(a4)){
a4.x=-30
}
}
ship.addEventListener(Event.ENTER_FRAME,resetA);*/
Copy link to clipboard
Copied
i've already answered this once:
either ship or a4 is null (ie, don't exist) when that line of code executes.
Copy link to clipboard
Copied
Good afternoon.
" a4 " and "ship " are movieclip , right? When you run the function " stage2 " checks if the condition is true , follows :
stage2 function ( evt : Event) : void
{
if ( ship.hitTestObject ( a4 ) ) { ( THIS IS LINE 103 )
gotoAndStop (128 );
/ / stage.removeEventListener ( KeyboardEvent.KEY_DOWN , moveShip ) ;
/ / stage.removeEventListener ( KeyboardEvent.KEY_DOWN , rotateShip ) ;
stage.removeEventListener ( Event.ENTER_FRAME , stage2 ) ;
stage.removeEventListener ( Event.ENTER_FRAME , loop ) ;
}
}
In marked line you remove the event from the "stage" but this event needs to be removed so movieclip "ship " , follows :
stage2 function ( evt : Event) : void
{
if ( ship.hitTestObject ( a4 ) ) { ( THIS IS LINE 103 )
gotoAndStop (128 );
/ / stage.removeEventListener ( KeyboardEvent.KEY_DOWN , moveShip ) ;
/ / stage.removeEventListener ( KeyboardEvent.KEY_DOWN , rotateShip ) ;
ship.removeEventListener ( Event.ENTER_FRAME , stage2 ) ;
stage.removeEventListener ( Event.ENTER_FRAME , loop ) ;
}
}