Game Problem

Hello, I’ve got a problem with a game. I’d like to be able to have the movie clips be both clickable and add text to the dynamic text box that I created. However, when I put this code into my fla file, nothing happens when I click on ball1, as indicated in the bottom part of the script. When I click on ball 1, i want to display the message in the dynamic text box and stop the movement of all 3 balls. Please help!!!

I’m new to AS3, so please hold your laughs when you look at the code. I really need help.

Thanks,
Robert.

     var ballSpeedX:int = -2;
     var ballSpeedY:int = -1;
     var ball1SpeedX:int = -2;
     var ball1SpeedY:int = -1;
     var ball2SpeedX:int = -2;
     var ball2SpeedY:int = -1;

     ball.buttonMode = true;
     ball1.buttonMode = true;
     ball2.buttonMode = true;

     init();

     function init():void
     {
     	stage.addEventListener(Event.ENTER_FRAME, loop);
     }

     function loop(e:Event):void
     {
     	ball.x += ballSpeedX;
     	ball.y += ballSpeedY;
     	ball1.x += ball1SpeedX;
     	ball1.y += ball1SpeedY;
     	ball2.x += ball2SpeedX;
     	ball2.y += ball2SpeedY;

     	//because the ball's position is measured by where its CENTER is...
     	//...we need add or subtract half of its width or height to see if that SIDE is hitting a wall
     	//first check the left and right boundaries
     	if(ball.x <= ball.width/2){ //check if the x position of the left side of the ball is less than or equal to the left side of the screen, which would be 0
     		ball.x = ball.width/2; //then set the ball's x position to that point, in case it already moved off the screen
     		ballSpeedX *= -1; //and multiply the ball's x speed by -1, which will make it move right instead of left

     	} else if(ball.x >= stage.stageWidth-ball.width/2){ //check to see if the x position of it's right side is greater than or equal to the right side of the screen, which would be 550
     		ball.x = stage.stageWidth-ball.width/2; //and set the x position to that, in case it already moved too far of the right side of the screen
     		ballSpeedX *= -1; //multiply the x speed by -1 so that the ball is now moving left

     	}

     	//now we do the same with the top and bottom of the screen
     	if(ball.y <= ball.height/2){ //if the y position of the top of the ball is less than or equal to the top of the screen
     		ball.y = ball.height/2; //like we did before, set it to that y position...
     		ballSpeedY *= -1; //...and reverse its y speed so that it is now going down instead of up

     	} else if(ball.y >= stage.stageHeight-ball.height/2){ //if the bottom of the ball is lower than the bottom of the screen
     		ball.y = stage.stageHeight-ball.height/2; //reposition it
     		ballSpeedY *= -1; //and reverse its y speec so that it is moving up now

     	}
     	if(ball1.x <= ball1.width/2){ //check if the x position of the left side of the ball1 is less than or equal to the left side of the screen, which would be 0
     		ball1.x = ball1.width/2; //then set the ball1's x position to that point, in case it already moved off the screen
     		ball1SpeedX *= -1; //and multiply the ball1's x speed by -1, which will make it move right instead of left

     	} else if(ball1.x >= stage.stageWidth-ball1.width/2){ //check to see if the x position of it's right side is greater than or equal to the right side of the screen, which would be 550
     		ball1.x = stage.stageWidth-ball1.width/2; //and set the x position to that, in case it already moved too far of the right side of the screen
     		ball1SpeedX *= -1; //multiply the x speed by -1 so that the ball1 is now moving left

     	}

     	//now we do the same with the top and bottom of the screen
     	if(ball1.y <= ball1.height/2){ //if the y position of the top of the ball1 is less than or equal to the top of the screen
     		ball1.y = ball1.height/2; //like we did before, set it to that y position...
     		ball1SpeedY *= -1; //...and reverse its y speed so that it is now going down instead of up

     	} else if(ball1.y >= stage.stageHeight-ball1.height/2){ //if the bottom of the ball1 is lower than the bottom of the screen
     		ball1.y = stage.stageHeight-ball1.height/2; //reposition it
     		ball1SpeedY *= -1; //and reverse its y speec so that it is moving up now

     	}
     if(ball2.x <= ball2.width/2){ //check if the x position of the left side of the ball2 is less than or equal to the left side of the screen, which would be 0
     		ball2.x = ball2.width/2; //then set the ball2's x position to that point, in case it already moved off the screen
     		ball2SpeedX *= -1; //and multiply the ball2's x speed by -1, which will make it move right instead of left

     	} else if(ball2.x >= stage.stageWidth-ball2.width/2){ //check to see if the x position of it's right side is greater than or equal to the right side of the screen, which would be 550
     		ball2.x = stage.stageWidth-ball2.width/2; //and set the x position to that, in case it already moved too far of the right side of the screen
     		ball2SpeedX *= -1; //multiply the x speed by -1 so that the ball2 is now moving left

     	}

     	//now we do the same with the top and bottom of the screen
     	if(ball2.y <= ball2.height/2){ //if the y position of the top of the ball2 is less than or equal to the top of the screen
     		ball2.y = ball2.height/2; //like we did before, set it to that y position...
     		ball2SpeedY *= -1; //...and reverse its y speed so that it is now going down instead of up

     	} else if(ball2.y >= stage.stageHeight-ball2.height/2){ //if the bottom of the ball2 is lower than the bottom of the screen
     		ball2.y = stage.stageHeight-ball2.height/2; //reposition it
     		ball2SpeedY *= -1; //and reverse its y speec so that it is moving up now

     	}
     }

     ball1.addEventListener(MouseEvent.CLICK, incorrectAnswer);

     function incorrectAnswer(e:MouseEvent):void
     {
     	ballSpeedX = 0;
     	ballSpeedY = 0;
     	ball1SpeedX = 0;
     	ball1SpeedY = 0;
     	ball2SpeedX = 0;
     	ball2SpeedX = 0;
     	feedback_txt.text = "You are right!";
     }

Looks to me like it should work. I’d double check all of the instance names and such, but the part of code you’re testing boils down to:

ball1.addEventListener(MouseEvent.CLICK, incorrectAnswer)

function incorrectAnswer(e:MouseEvent):void {
	feedback_txt.text = "You are right!"
}

…which is pretty straightforward and should work unless I’m missing something silly.

Check the error console to make sure that nothing else is breaking and stopping that code from working.