Unable to get multiplayer section of pong game working despite proper code -- or so I think
Hey everyone,
there is a problem that I am encountering on a test pong game that I was creating.
My "singleplayer" section of my pong game works perfectly fine
However my "multiplayer" section, when clicked on, despite setting code to it (with new variables), does not work, I get the following error:
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at _6_Test_Pong_fla::MainTimeline/frame3()
at flash.display::MovieClip/gotoAndStop()
at _6_Test_Pong_fla::MainTimeline/fl_ClickToGoToAndStopAtFrame_4()
My code:
For frame 1:
/* Stop at This Frame
The Flash timeline will stop/pause at the frame where you insert this code.
Can also be used to stop/pause the timeline of movieclips.
*/
stop();
/* Click to Go to Frame and Stop
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.
Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
*/
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_2);
function fl_ClickToGoToAndStopAtFrame_2(event:MouseEvent):void
{
gotoAndStop(2);
}
/* Click to Go to Frame and Stop
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.
Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
*/
function fl_ClickToGoToAndStopAtFrame_3(event:MouseEvent):void
{
gotoAndStop(2);
}
/* Click to Go to Frame and Stop
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.
Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
*/
button_3.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_4);
function fl_ClickToGoToAndStopAtFrame_4(event:MouseEvent):void
{
gotoAndStop(3);
}For frame 2:
/* DECLARE VARIABLES */
var xMove = 5; // variable for ball movement on x-axis
var yMove = 5; // variable for ball movement on y-axis
/* Enter Frame Event
Executes the function fl_EnterFrameHandler defined below each time the playhead moves into a new frame of the timeline.
Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the playhead moves into a new timeline frame.
*/
var score = 0; // variable for starting score
scoreBox.text = score;
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
function fl_EnterFrameHandler(event:Event):void
{
//Start your custom code
// This example code displays the words "Entered frame" in the Output panel.
ball.x += xMove;
ball.y += yMove;
// test wall hits
if (ball.hitTestObject(wallRight)) {
xMove *= -1;
} else if (ball.hitTestObject(wallBottom)){
yMove *= -1;
} else if (ball.hitTestObject(wallLeft)){
xMove *= -1;
}else if (ball.hitTestObject(wallTop)){
yMove *= -1;
} // end wall hits
// test paddle hits
if (ball.hitTestObject(paddle)) {
yMove*= -1;
score +=1;
scoreBox.text = score;
} // end paddle hits
// End your custom code
}
/* Move with Keyboard Arrows
Allows the specified symbol instance to be moved with the keyboard arrows.
Instructions:
1. To increase or decrease the amount of movement, replace the number 5 below with the number of pixels you want the symbol instance to move with each key press.
Note the number 5 appears four times in the code below.
*/
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
paddle.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);
function fl_MoveInDirectionOfKey(event:Event)
{
if (upPressed)
{
paddle.y -= 5;
}
if (downPressed)
{
paddle.y += 5;
}
if (leftPressed)
{
paddle.x -= 5;
}
if (rightPressed)
{
paddle.x += 5;
}
}
function fl_SetKeyPressed(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = true;
break;
}
case Keyboard.DOWN:
{
downPressed = true;
break;
}
case Keyboard.LEFT:
{
leftPressed = true;
break;
}
case Keyboard.RIGHT:
{
rightPressed = true;
break;
}
}
}
function fl_UnsetKeyPressed(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = false;
break;
}
case Keyboard.DOWN:
{
downPressed = false;
break;
}
case Keyboard.LEFT:
{
leftPressed = false;
break;
}
case Keyboard.RIGHT:
{
rightPressed = false;
break;
}
}
}For frame 3:
/* DECLARE VARIABLES */
var xMove1 = 5; // variable for ball movement on x-axis
var yMove1 = 5; // variable for ball movement on y-axis
/* Enter Frame Event
Executes the function fl_EnterFrameHandler defined below each time the playhead moves into a new frame of the timeline.
Instructions:
1. Add your custom code on a new line after the line that says "// Start your custom code" below.
The code will execute when the playhead moves into a new timeline frame.
*/
var score1 = 0; // variable for starting score
scoreBox2.text = score;
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);
{
//Start your custom code
// This example code displays the words "Entered frame" in the Output panel.
ball2.x += xMove1;
ball2.y += yMove1;
// test wall hits
if (ball2.hitTestObject(wallRight2)) {
xMove1 *= -1;
} else if (ball2.hitTestObject(wallBottom2)){
yMove1 *= -1;
} else if (ball2.hitTestObject(wallLeft2)){
xMove1 *= -1;
}else if (ball2.hitTestObject(wallTop2)){
yMove1 *= -1;
} // end wall hits
// test paddle hits
if (ball2.hitTestObject(paddle2)) {
yMove1*= -1;
score +=1;
scoreBox2.text = score;
} // end paddle hits
// End your custom code
}
/* Move with Keyboard Arrows
Allows the specified symbol instance to be moved with the keyboard arrows.
Instructions:
1. To increase or decrease the amount of movement, replace the number 5 below with the number of pixels you want the symbol instance to move with each key press.
Note the number 5 appears four times in the code below.
*/
var upPressed1:Boolean = false;
var downPressed1:Boolean = false;
var leftPressed1:Boolean = false;
var rightPressed1:Boolean = false;
paddle2.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);
stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);
function fl_MoveInDirectionOfKey1(event:Event)
{
if (upPressed)
{
paddle2.y -= 5;
}
if (downPressed)
{
paddle2.y += 5;
}
if (leftPressed)
{
paddle2.x -= 5;
}
if (rightPressed)
{
paddle2.x += 5;
}
}
function fl_SetKeyPressed1(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = true;
break;
}
case Keyboard.DOWN:
{
downPressed = true;
break;
}
case Keyboard.LEFT:
{
leftPressed = true;
break;
}
case Keyboard.RIGHT:
{
rightPressed = true;
break;
}
}
}
function fl_UnsetKeyPressed1(event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.UP:
{
upPressed = false;
break;
}
case Keyboard.DOWN:
{
downPressed = false;
break;
}
case Keyboard.LEFT:
{
leftPressed = false;
break;
}
case Keyboard.RIGHT:
{
rightPressed = false;
break;
}
}
}
If needed, here is the link to my animate file:Uploadfiles.io link to my file
Anyone have any idea how I fix this? Any help would be appreciated.
