Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating a Pong game in AS3 using a tutorial

Contributor ,
Sep 28, 2011 Sep 28, 2011

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 1171093: Syntax error.
C:\Users\xxx\Desktop\P4\Main.as, Line 1171084: Syntax error: expecting rightparen before 270.
C:\Users\xxx\Desktop\P4\Main.as, Line 1211093: Syntax error.
C:\Users\xxx\Desktop\P4\Main.as, Line 1211084: 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

TOPICS
ActionScript
3.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 28, 2011 Sep 28, 2011

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 28, 2011 Sep 28, 2011
LATEST

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines