Creating a Pong game in AS3 using a tutorial
Copy link to clipboard
Copied
Hi,
I'm a beginner using AS3 and found a great tutorial on how to create a Pong game: http://www.foundation-flash.com/tutorials/pong4/. There's a link to the source code: http://www.foundation-flash.com/source/viewer.php?file=pong4.txt.
When I add the source code to a new AS file (using Flash CS 5.5), save it as "Main.as", create a new Fla and link it in the actionscript settings to the Main.as and run it, I get errors:
C:\Users\xxx\Desktop\P4\Main.as, Line 117 | 1093: Syntax error. |
C:\Users\xxx\Desktop\P4\Main.as, Line 117 | 1084: Syntax error: expecting rightparen before 270. |
C:\Users\xxx\Desktop\P4\Main.as, Line 121 | 1093: Syntax error. |
C:\Users\xxx\Desktop\P4\Main.as, Line 121 | 1084: Syntax error: expecting rightparen before 270. |
Here's the section of code being referred to in the error message:
116 public function resetHandler(e:Event){
117 if(ball.x < (0 – 270)){
scoreText2.text = String(Number(scoreText2.text ) + 1)
reset();
}
121 if(ball.x > (550 – 270)){
scoreText1.text = String(Number(scoreText1.text ) + 1)
reset();
}
}
I must be doing something wrong? Is there some way to get this code and Pong game sample running ?
Any help would be appreciated.
Regards,
saratogacoach

Copy link to clipboard
Copied
You most likely pasted the script from that source. The - in those lines is probably an n-dash or something. Replace with a minus and you should be ok.
i.e (0 - 270) and (550 - 270)
Copy link to clipboard
Copied
As Raymond said, its an issue with the 'dashes' in your if statements; they need to be minus signs, its just the wrong character.
On a related note..why are you (the tutorial?) doing basic equations in a conditional statement? 0 – 270
and 550 – 270
are always going to be the same value...why compute it on every check?

