Creating a Pong game in AS3 using a tutorial

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

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?

Similar Messages

  • How to create a multiplayer game for steam using flash/flex?

    Hi guys,
    We've got a multiplayer game ready to go. Currently it is not multiplayer, but we'd like to get it to a stage where it can be played over the steam network by users of steam and owners of steam games.
    We'd like to if anyone could briefly give us a breakdown of how to get out game up on steam and available for multiplayer?
    Does steam host servers, and can we utilise a steam server to transfer data between players or would we have to run our own server?
    Currently were using flash builder to publish via adobe air to a windows desktop exe. Can anyone briefly explain how - once a player has downloaded the game from steam we can connect two players? Does anyone know how to use actionscript 3 to access steam network?
    Anyone have any experience developing multiplayer turn based game for steam using flash /actionscript 3 /adobe air?
    Thanks for your help in advance,
    i

    You would want to use the SteamWorks API, which is available from Steam as a C++ library, but there is most likely an Adobe Native Extension (ANE) that would allow you to use the library in AS3.
    I've never used SteamWorks but it seems to support peer-2-peer matchmaking (in other words, you wouldn't even need your own server, I think.)
    SteamWorks API:
    https://partner.steamgames.com/documentation/api
    Search results for "SteamWorks AIR ANE":
    https://www.google.com/search?q=steamworks+air+ane
    -Aaron

  • Code for a pong game written in C++

    Hi there
    I have this computer graphics project, to implement a pong game written C++, using openGL. I have never done such a project before and I'm not keen to C++. Thus, if anyone have the code of a pong game written in C++, please don't hesitate to help me...
    Thankx in advance

    Why not create a DLL?  It doesn't have to be in C -- I was using one done in C# today and have also used DLL's written in C++.  If you can make it into a DLL, LabVIEW can call it (although there are certain details like pointers and structures that have to be taken care of.
    If you want to use a CIN, keep in mind that just about everything you pass back will have to be done with a file....
    -Matt Bradley
    ************ kudos always appreciated, but only when deserved **************************

  • Creating a matching game.

    So I would like to create a matching game in captivate using advanced action.
    The goal is for the learner to on click;
    Reveal a card then reveal another card, if it does not match hide both.
    If they do match they stay revealed and their actions disable so that other cards do not affect them.
    The process is then repeated with the other cards until all are matched

    Hello and welcome to the forum,
    Is this what you want?
    http://blog.lilybiri.com/concentration-game-created-exclusively-with-c
    I created this with CP5.5, now it is a lot easier in 6/7 with groups and shapes. Look at this video:
    http://www.youtube.com/watch?v=Sy09xPoP69A
    And in 7, with the shared actions, even easier. No documentation written for that (yet)
    Lilybiri

  • Can I create an iOS game using C++?

    I want to create games for iOS using C++ and Maya? Please help me. Tell me what I need to know. Thanks!

    I do not have Flash CS6 (too many bug reports) but I use it perfectly fine in CS5.5.
    What your error means is basically the libraries are not the latest and what it's trying to export to is a lower version than is supported. It runs on Desktop because you've updated your desktops AIR to 3.2 and have flash player 11.0 or better. For AIR for iOS, you need to make absolutely sure it is packaging with AIR 3.2 or higher. Flash CS6 might be targeting something below AIR 3.2.
    Here are instructions for overlaying the latest version of AIR on Flash. This should give you an idea of what to check in your version of Flash. Go through the list item by item and check the files in the locations that are mentioned and make sure the versions are at least the same.
    http://helpx.adobe.com/x-productkb/multi/overlay-air-sdk-flash-professional.html
    If you jump ahead to step 4 you should be seeing in those files a version="15". You should also see in step 6 that the namespace AIR is pointing to is at least 3.2. If either are lower you may need to update your version of AIR, and there are the instructions to do so. Although the AIR folder will probably not be named AIR2.6 of course. But the instructions should be similar.

  • Code i use to increase the difficulties on a flash pong game?

    i need code to apply on my flash game to make the pong game more difficult as the game goes on.
    help?

    lwood655 wrote:
    I changed the passcode needed to open my phone,  when I try to do a restore on this phone, it is asking for a passcode and not accepting the one I changed it to
    There are several different passcodes associated with any iOS device:
    The screen unlock passcode. This is normally a 4 digit code (although there is an option to make it longer).
    Your iCloud passcode. This controls Find my iPhone and Activation Lock, the theft deterrent measure that prevents a stolen or lost phone from being used. This will be prompted for if Find my iPhone is enabled when you restore the phone.
    Possibly the passcode to unlock an encrypted backup, as @Drew Reece pointed out.

  • Desktop multiplayer ping-pong game

    Hello all,
    I've come here to seek advice related to my university project. I am almost a complete newbie at Java - during the past years I've only done programming in C, C++, Symbian and PHP. I remember doing a project in Java on the first year, but now I don't remeber anything.
    Let's get to the point. I think I won't have problems with the language itself and the structure of the application. Yet, I would be very grateful if you could guide me to the resources/libraries/classes I should use in my project.
    It will be a multiplayer network ping-pong game in a frame window, with a game frame, some menubar and a chat below the game frame. My question is: what class should I use to create a window for the whole application? What class for the game screen, where it will be neccesary to paint a ball jumping here and there and two rackets? What classes would you recommend for handling the network communication between two instances of the application? Any other suggestions would also be welcome. I have less than three weeks to implement this game:)
    Thanks in advance.
    Maciej Gawronski

    I guess you haven't taken the google class yet...
    http://www.softlookup.com/tutorial/games/ch2.asp
    http://javaboutique.internet.com/tutorials/Java_Game_Programming/
    Edited by: Mr.E.H. on Jan 2, 2008 3:01 PM

  • Pong Game - HELP

    Hi guys, I'd firstly like to apologise if I've posted in the wrong forum - as you've moved probably guessed, I'm new round "there here parts"! :P
    I recently started attempting some basic java graphics in a swing. So far, everything is working but I have the following questions:
    1) How do I stop the graphics flickering? - I know it's due to the thread refresh rate in the continuous loop, but can I stop the flickers?
    2) How do I add a JPanel ABOVE the canvas in which I can add buttons to restart the game? - I assume it would involve a GridBagLayout which I'm unfamiliar with, so your assistance would be appreciated. Note: I'll only need assistance in adding the JPanel above the canvas, I can do the rest! :)
    My current code is shown below - please don't complain about imperfections, as it's just a development:
    import javax.swing.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.awt.*;
    public class Pong
       private static JFrame frame;
       private static Canvas canvas;
       private static KeyListener listener;
       private static boolean inPlay = true;
       private static boolean gamePaused = false;
       private static int yP1 = 160;
       private static int yP2 = 160;
       private static Graphics Bgfx;
       private static boolean update = false;
       private static BufferedImage bi;
       private static int ballPosx = 600;
       private static int ballPosy = 200;
       private static int ballXSpeed = 1;
       private static int ballYSpeed = 1;
       private static int ballOffSetx = 1;
       private static int ballOffSety = -1;
       private static int paddleSpeed = 10;
       private static boolean winnerP1 = false;
       private static boolean winnerP2 = false;
       //Upper panel variables
       private static JPanel upperPNL;
       private static JButton restartButton;
       private static GridBagConstraints gbc;
       public static void main (String args[])
          //Initialize GUI
          frame = new JFrame("Pong Game");
           //Canvas / frame parameters
          canvas = new Canvas();
          canvas.setSize(1200, 500);
           //Content pane
           Container content = frame.getContentPane();
           content.add(canvas);
          frame.setIgnoreRepaint(true);                
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
          frame.pack();
          frame.setVisible(true);
           frame.addKeyListener(listener);
           frame.addKeyListener(new KeyListener() {
              public void keyPressed(KeyEvent e) {
                   if (e.getKeyCode() == 'Q') {
                        if (yP1 > 20) {
                             yP1 -= paddleSpeed;
                             update = true;
                      if (e.getKeyCode() == 'A') {
                           if (yP1 < 380) {
                             yP1 += paddleSpeed;
                             update = true;
                   if (e.getKeyCode() == 'P') {
                        if (yP2 > 20) {
                             yP2 -= paddleSpeed;
                             update = true;
                   if (e.getKeyCode() == 'L') {
                        if (yP2 < 380) {
                             yP2 += paddleSpeed;
                             update = true;
                   public void keyReleased(KeyEvent e) {
                   update = false;
                    public void keyTyped(KeyEvent e) {}
          gameLoop(canvas.getGraphics());                     //Begin Game Loop
       private static void gameLoop(final Graphics gfx)
          //Create a BufferedImage to use it's graphics.
          bi = new BufferedImage(1200, 500, BufferedImage.TYPE_INT_RGB);
          //While the game isn't paused
          while(inPlay)
         while(!gamePaused)
              try
                      Thread.sleep(1);
              catch(Exception ex)
                   System.out.println("Interrupted Sleep");
              gameRender(bi, gfx);
              moveBall();
              checkCollisions();
       private static void moveBall()
              if (winnerP1 || winnerP2) { ballOffSety = 0; ballOffSetx = 0; }
              ballPosx += ballXSpeed * ballOffSetx;
              ballPosy += ballYSpeed * ballOffSety;
              if (ballPosy < 0) {
                   ballOffSety *= -1;
              if (ballPosy > 500) {
                   ballOffSety *= -1;
              if (ballPosx < 0) {
                   ballOffSetx *= -1;
              if (ballPosx > 1200) {
                   ballOffSetx *= -1;
         private static void checkCollisions() {
              if ((ballPosx >= 72 && ballPosx <= 107) && (ballPosy >= yP1 && ballPosy <= (yP1 + 100)))
                   ballOffSetx *= -1;
              if ((ballPosx >= 1072 && ballPosx <= 1107) && (ballPosy >= yP2 && ballPosy <= (yP2 + 100)))
                   ballOffSetx *= -1;
              if (ballPosx < 107)
                   winnerP2 = true;
              if (ballPosx > 1107)
                   winnerP1 = true;
       private static void gameRender(BufferedImage bi, Graphics gfx)
           if (winnerP1) {
              bi.getGraphics();
              Font font = new Font("Arial", Font.PLAIN, 36);
              gfx.setFont(font);
              gfx.setColor(Color.RED);
              gfx.drawString("PLAYER 1 WINS!!!", 520, 200);
              gfx.drawImage(bi, 0, 0, null);
           if (winnerP2) {
              bi.getGraphics();
              Font font = new Font("Arial", Font.PLAIN, 36);
              gfx.setFont(font);
              gfx.setColor(Color.RED);
              gfx.drawString("PLAYER 2 WINS!!", 520, 200);
              gfx.drawImage(bi, 0, 0, null);
          //Get Buffered Graphics to Draw To
          Bgfx = bi.getGraphics();
          //Draw Background
          Bgfx.setColor(Color.BLACK);
          Bgfx.fillRect(0,0,1200,500);
          //Draw Bar 1
          gfx.setColor(Color.GREEN);
           gfx.fillRect(72,yP1,35,100);
          //Draw Bar 2
          gfx.fillRect(1072,yP2,35,100);
          //Draw Ball
          gfx.fillRect(ballPosx,ballPosy,20,20);
          //Draw the Buffered Graphics to the screen
          gfx.drawImage(bi, 0, 0, null);
    }Constructive criticism is welcomed, but major edits which I'm not likely to understand as of yet are not.
    Many thanks for your assistance, it's appreciated.
    Edited by: -Barto- on Jun 30, 2010 5:21 PM

    -Barto- wrote:
    Hi guys, I'd firstly like to apologise if I've posted in the wrong forum - as you've moved probably guessed, I'm new round "there here parts"! :PWelcome, and not to worry -- this is the correct forum for your question.
    I recently started attempting some basic java graphics in a swing. So far, everything is working but I have the following questions:
    1) How do I stop the graphics flickering? - I know it's due to the thread refresh rate in the continuous loop, but can I stop the flickers?
    2) How do I add a JPanel ABOVE the canvas in which I can add buttons to restart the game? - I assume it would involve a GridBagLayout which I'm unfamiliar with, so I think that you're main problem is that you're trying to mix AWT components (i.e., Canvas) and Swing components (everything else) in one program. In addition, you need to update your game loop and graphics to be in line with Swing best practices. So, get rid of Canvas, read up in the tutorials on how to do graphics in Swing (using paintComponent override for instance) and use a Swing Timer for your Game loop and you'll be half way there. Best of luck!

  • Creating a jeopardy game

    Hi,
    I'd like to create a Jeopardy game using the interaction widget but am encourntering a ton of problems.
    First off often the information I input is no longer there after I leave the window in whcih I wrote it. Second, when I put anything in French in doesn't save (is there a way around this).
    Third, can the categories be longer than a few caracters?
    I am working in Captivate 7.
    Thank you!

    Hi
    I've had a look at your zip files, and with the best will in the world what your asking for is way beyond what one individual here is willing to invest.
    First of all, this is AS2.0 on the Timeline, most Coders don't do this anymore. It's AS3.0 and Classes now.
    If your able to invest a little time and patient in learning AS3 the rewards are far greater.
    I'm sorry this might not be the answer you where looking for, but it's best you find out now than waiting indefinitely and getting no further with your project.
    Best Regards
    The Feldkircher

  • Creating Flash Board Game (Multiplayer online)

    Hi,
    Right now i am doing on a project on Chinese Checkers which
    have 2 players, 3 players, 4 players, 6 players. I used SQL Server
    as database. game programmed in AS3, and i used web services to
    connect them. I used Timers to get data Consistently as Web
    services does not support data push like flash remoting. Due to
    budget issue, i have to use web service in my project for
    educational learning.
    I have created game lobby in flash, where user can chat, see
    whose online, and create or join game. One main question: Can i do
    all of them in frames without using external actionscript
    files?like coding in first frame.
    1st swf: Game Lobby --> press create button --> 2nd
    swf: Game Create Border -->3rd swf: Press 2 , 3 ,4 or 6 players
    button -> 4th swf: Game.

    an as2 swf will work when loaded by an as3 swf. the two can
    communicate using the localconnection class.

  • Creating an ajustable 3d shape (without using any plugins, Away 3D etc).

    I followed this youtube video:
    http://www.youtube.com/watch?feature=endscreen&NR=1&v=PfR9n0eZJvs
    And I created a 3D cube in flash using the 3D rotation tool and registration points. I know it isnt truely 3D it more like 2.5D.
    I have the finish item and its cool but I was wondering, how would I go about using actionscript to edit the cube. I would ideally like to be able to edit the size of the cube maybe extrude it in some way. Also how could I spin it on its axis In a similar way to using the 3D rotation tool.
    I dont know how to do these things without ruining the effect on the cube itself.
    Im relatively new to Flash and AS3 but im trying to really emerse myself until I have really mastered it at a high level. Any help would be greatly appreciated.
    Cheers
    Fred

    convert your cube to a movieclip and use its 3d properties.

  • My two iPads share an Apple ID.  How can I create a separate Game Center account so they can play each other?

    My two iPads share an Apple ID.  How can I create a separate Game Center account so they can play each other?

    1. This is a year old post.  Things have changed, the answer is no longer accurate due to how the OS functions now.
    2.  You can't have a second Gamecenter account tied to the same Apple ID, because the Apple ID is the game center account.  They are not separate things.
    3. The OP said they had 2 iPads, which means they can use a different Apple ID for Gamecenter on the second iPad.
    4. You can still creare Apple ID's specifically for game center without changing them for the other services on the other devices.
    ronjack wrote:
    I have the same issue.  Young children who cannot get Apple ID's but we all want separate Gamecenter accounts.
    You need to get Apple ID's for them.  They aren't getting them, you are. You can manage these new ID{s yourself. You can even make sure they have no credit card and are not associated with any other service on the device. So essentially they are Apple ID's for GameCente only.

  • Help needed to create a master-detail JSP page using OAF.

    I like to create a master-detail JSP page using OAF. If any help or guide will be appreciate.
    - Kausik

    A Master Detail Page is a basically a game between two VOs(Master and Detail mostly connected through a View Link). You can also have a look at the View Link section in the Dev guide. Page Layouts is one thing which you can take a call yourself.
    Regards
    Sumit

  • Pong Game Problem

    I have a problem with my pong game. IT says its missing a return statement at :71: and at someplace else. How do I fix this? Below is the source code. Note that I haven't done puck-paddle collisions yet. It isn't supposed to do those right now anyway, so please try to fix the return statement problem, not that. Here is the code:
    import java.applet.*;
    import java.awt.*;
    public class Ponggame extends Applet implements Runnable
         int score = 0;
         int otherscore = 0;
         int y_speed = 0;
         int other_y_speed = 0;
         int appletsize_x = 640;
         int appletsize_y = 480;     
         int xpos = 620;
         int ypos = 220;
         int otherxpos = 20;
         int otherypos = 220;
         int ball_xpos = 130;
         int ball_ypos = 130;
         int radius = 20;
         int ball_xspeed = 2;
         int ball_yspeed = 2;
         int paddle_width = 32;
         int paddle_height = 80;
         int other_paddle_width = 32;
         int other_paddle_height = 32;
         //Variables for Double Buffering
         private Image dbImage;
         private Graphics dbg;
         public void init()
              setBackground (Color.black);
         public void start()
              Thread th = new Thread (this);
              th.start ();
         public void stop()
         public void destroy()
         public boolean keyDown (Event e, int key)
              if (key == Event.UP)
                   y_speed = -2;
              else if (key == Event.DOWN)
                   y_speed = 2;
              else if (key == 119)
                   other_y_speed = -2;
              else if (key == 115)
                   other_y_speed = 2;
         public boolean keyUp (Event e, int key)
              if (key == Event.UP)
                   y_speed = 0;
              else if (key == Event.DOWN)
                   y_speed = 0;
              if (key == 119)
                   other_y_speed = 0;
              else if (key == 115)
                   other_y_speed = 0;
         public void run()
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              while (true)
                   if (ball_xpos > appletsize_x - radius)
                        otherscore += 1;
                        ball_xpos = 120;
                        ball_ypos = 120;
                   else if (ball_xpos < radius)
                        score += 1;
                        ball_xpos = 120;
                        ball_ypos = 120;     
                   else if (ball_ypos > appletsize_y - radius)
                        y_speed = -2;
                   else if (ball_ypos < radius)
                        ball_yspeed = +2;
                   else if (ypos<0)
                        ypos = 0;
                   else if (ypos+paddle_height>appletsize_y)
                        ypos = (appletsize_y - paddle_height);
                   else if (otherypos<0)
                        otherypos=0;
                   else if (otherypos+other_paddle_height>appletsize_y)
                        otherypos = (appletsize_y - other_paddle_height);
                   ypos += y_speed;
                   otherypos += other_y_speed;
                   ball_xpos += ball_xspeed;
                   ball_ypos += ball_yspeed;
                   // Neuzeichnen des Applets
                   repaint();
                   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
         public void paint (Graphics g)
              g.setColor (Color.red);
              g.fillOval (ball_xpos - radius, ball_ypos - radius, 2 * radius, 2 * radius);
              g.setColor (Color.white);
              g.fillRect (xpos, ypos, paddle_width, paddle_height);
              g.fillRect (otherxpos, otherypos, other_paddle_width, other_paddle_height);
    }

    Your public boolean keyXXX methods don't return a boolean.
    And use code tags when posting code. There is a code button above the message editor.

  • The ever so savvy "creating a java game" post

    Hey, I'm creating a java game, and I did research, and found that this question has been asked many, many times. But my question unfortunately did not match up with any of these posts :( So here goes...
    Im creating a java game, which will run as....kind of a mix between a 2d game, and 3d game (no i am not insane). I dont want the original zelda look, and i dont want the first person shooter look, I want my character to be viewed from an angle, like tibia - if anyone has ever played that. And I also want to leave open the door to changing the view within the game. I figured I can just get my graphics friends to draw things in 3-d, (draw a house [draw the 4 sides and the roof]), and then somehow skew these images to accomodate for a different view.
    I am more than willing to code some kind of graphics engine if what I need is not available, I have looked at a couple and found no such luck.
    So what is the most efficient way to create this game? By just sortof getting all the graphics to be from a certain percpective, and then somehow modifying them with java.....
    or by using some kind of graphics engine that allows me to change views? If so any recomendations?
    Thanks a lot - wow this was long, oh yea a couple Dukes for this too thanks again
    -Mark

    you don't need to do any skewing. Here's what I'd do. I'd store all the tile information in a matrix (Object[][]) with a custom tile class that has the information it needs to retrieve its appropriate image, and certain game related data like slow down factor when a person walks over a certain type of tile, and whether it can be collided with. I'd draw them based on however you decide to angle your tiles. But the important part is you go in this order:
    [0, 0], [0, 1], [1, 0], [0, 2], [1, 1], [2, 0], etc., etc....
    The idea is if you're turning the floor 45 degrees clockwise, to give the correct illusion of depth, you'll want to draw the furthest back tile first, and the furthest tile forward last. Whether you start on the left or right depends on what angle you decide to work with. At a 45 degree angle, it obviously doesn't matter whether you start on the left or right. But if you guess wrong with your rendering, it will show because tiles that are closer to the "camera" will be overlapped by tiles further from the "camera".
    for (int i = 0; i < tiles.length; i++) {
         for (int j = 0; j < tiles.length; j++) {
              graphics2D.drawImage(tiles[i].getImage(), i*horizontalSpacing - camera.getX(), j*verticalSpacing, camera.getY(), null);
    }horizontalSpacing and verticalSpacing will be determined by the angle of your tiles. Set those to match however you make your art.
    Drawing moving sprites will be a bit trickier because you'll have to decide which set of axes to follow... meaning, do you follow the axes of the screen, or the axes of your "rotated world." Give that some thought and once you understand what's happening with the perspective here you'll be able to see which is easiest.
    So there's your engine ;)
    Now, as for the art itself, make them in png format, so that you can have the base of your images be diamond shape, but of course tiles for players and walls and stuff will extend above that diamond. Just don't let them get below the base of their diamond otherwise the tile that gets drawn below them will cut them off. And you don't want a character's feet cut off by the "floor" as he runs ;)
    For your final question, don't let java skew the sprite. The only possible way to make it decent is if when you pick an angle, a 3D render takes your 3D world and it's 3D models and re-renders them at that angle; skewing is simply not capable of creating that illusion. The closest you could get is to simply squish the hight of your art to give the illusion that the camera is moving up, but since you can't expose things higher, like the top of your character's head (since the data doesn't exist in the "lower" version), it will be obviously funny looking.
    Hope that answers your questions, and good luck! I would definitely like to see what you come up with.

Maybe you are looking for