17 Replies Latest reply on Jul 11, 2011 5:12 AM by Ned Murphy

    Please help. keyPress not working

    Bobbyloujo

      I'm new the Flash but I have some other programming experience. I just started using Flash today and I could use some help.

       

      I have two squares on the screen. One is white, one is black. Both squares have the same code:

       

      onClipEvent(load){
          speed = 3;
      }
      onClipEvent(enterFrame){
          if(_y < 512){
              _y = _y + speed;
          }
      }
      on(keyPress "<Left>"){
          _x -= 18;
      }
      on(keyPress "<Right>"){
          _x += 18;
      }

       

      Here's what I think should happen: The squares fall at 3 pixels per frame until they hit 512 or greater. If the left button is pressed, both squares go left. If the right but is pressed, both squares go right.

       

      The first part works fine. The squares fall until the get to 512. Here's where I'm confused: when I press left or right, only the white square moves even though both squares have the same code. Why is this?

       

      If you need me to provide the source I will.