0
votes

I am coding a flash game in which the ball hits a movie clip object and this takes the user to a new scene. I have 3 main methods: movePaddle, moveBall and changeFrame.

it works fine but when i execute the changeFrame method (ball hits movie clip)to go to a new frame i get a whole page of 1009 errors:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FlashGameNEW_fla::MainTimeline/changeFrame()

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FlashGameNEW_fla::MainTimeline/movePaddle()

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FlashGameNEW_fla::MainTimeline/moveBall()

This is repeated many times.

Any help would be greatly appreciated. Thanks.

EDIT: with code below

function beginCode():void{

mcPaddle.addEventListener(Event.ENTER_FRAME, movePaddle);
mcBall.addEventListener(Event.ENTER_FRAME, moveBall);
mcBall.addEventListener(Event.ENTER_FRAME, changeFrame);
}

function movePaddle(event:Event):void{

mcPaddle.x = mouseX - mcPaddle.width / 2;

if(mouseX < mcPaddle.width / 2){
    //Keep the paddle on stage
    mcPaddle.x = 0;
}

if(mouseX > stage.stageWidth - mcPaddle.width / 2){

    mcPaddle.x = stage.stageWidth - mcPaddle.width;
}
}

function changeFrame(event:Event):void{
if (mcBall.hitTestObject(Northcote)) {  
    this.gotoAndPlay(3);  
              }
              
}
1
it would be a lot more helpful if we could see your code - WebChemist
code added hope this is ok - user1982108
do your instances (mcPaddle, mcBall, etc) exist on frame 3? - gthmb

1 Answers

1
votes

The problem is you havent instances of mcPaddle and mcBall in frame 3 (For instance, they are not created right now and will be created later). Do check for existing instance:

function movePaddle(event:Event):void {    
    if (!mcPaddle)
        return;

    mcPaddle.x = mouseX - mcPaddle.width / 2;

    if(mouseX < mcPaddle.width / 2){
        //Keep the paddle on stage
        mcPaddle.x = 0;
    }

    if(mouseX > stage.stageWidth - mcPaddle.width / 2) {    
        mcPaddle.x = stage.stageWidth - mcPaddle.width;
    }
}

function changeFrame(event:Event):void{
    if (mcBall && Northcote && mcBall.hitTestObject(Northcote)) {  
        this.gotoAndPlay(3);  
    }    
}