4 Replies Latest reply on Jul 25, 2011 7:41 PM by Celebrinborn

    Can someone please help me see my mistake?

    Celebrinborn

      I am creating a shogi game in flash using action script 2. My code is below. It worked just fine until I entered the cDown part and then, any time I press the c button, flash crashes. Does anyone know why this is/where my mistake is? Can someone please show me how to fix it? Thanks a ton.

      PS: according to google search engine, || means a logical "or", is this correct?

       

      gotoAndStop(1);

      var pDown = false;

      var cDown = false;

      frame_pawn_a1 = 1;

      var keyListener:Object = new Object();

      Key.addListener(keyListener);

       

      keyListener.onKeyDown = function() {

      if (Key.getCode() == 80) {// key p

      pDown = true;

      }

      if (Key.getCode() == 67) {//key c

      cDown = true;

      }

      };

      keyListener.onKeyUp = function() {

      if (Key.getCode() == 80) {// key p

      pDown = false;

      }

      if (Key.getCode() == 67) {//key c

      cDown = false;

      }

      };

      pawn_a1.onRelease = function() {// the mc click code

      if (pDown) {

      if (frame_pawn_a1 == 1) {

      pawn_a1.gotoAndStop(2);

      frame_pawn_a1 = 2;

      }

      if (frame_pawn_a1 == 3) {

      pawn_a1.gotoAndStop(4);

      frame_pawn_a1 = 4;

      }

      }

      if (cDown) {

      if (frame_pawn_a1 == 1 || 2) {

      pawn_a1.gotoAndStop(3);

      frame_pawn_a1 = 3;

      }

      if (frame_pawn_a1 == 3 || 4) {

      pawn_a1.gotoAndStop(1);

      frame_pawn_a1 = 3;

      }

      }

      };

        • 1. Re: Can someone please help me see my mistake?
          Ned Murphy Adobe Community Professional & MVP

          Yes, || is the logical OR, but the way you have it implemented is wrong.  You need to provide complete evaluations...

           

          if (frame_pawn_a1 == 1 || 2) {

           

          should be

           

          if (frame_pawn_a1 == 1 || frame_pawn_a1 == 2) {

           

           

          Or what you could otherwise do is....

           

          if (cDown) {

             if (frame_pawn_a1 <= 2) {

                pawn_a1.gotoAndStop(3);

                frame_pawn_a1 = 3;

             } else if (frame_pawn_a1 <= 4) {

                pawn_a1.gotoAndStop(1);

                frame_pawn_a1 = 3;

             }

          }

          1 person found this helpful
          • 2. Re: Can someone please help me see my mistake?
            Celebrinborn Level 1

            I still get either a "not responding message" or the message "A script in this movie is causing Flash Player to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?" everytime I click on pawn_1 and press c. If I click on pawn_1 and press p it works just fine however. Any ideas? If it would help I could upload the .fla file

             

            edit: My code currently is:

             

            gotoAndStop(1);

            var pDown = false;

            var cDown = false;

            frame_pawn_a1 = 1;

            var keyListener:Object = new Object();

            Key.addListener(keyListener);

             

            keyListener.onKeyDown = function() {

            if (Key.getCode() == 80) {// key p

            pDown = true;

            }

            if (Key.getCode() == 67) {//key c

            cDown = true;

            }

            };

            keyListener.onKeyUp = function() {

            if (Key.getCode() == 80) {// key p

            pDown = false;

            }

            if (Key.getCode() == 67) {//key c

            cDown = false;

            }

            };

            pawn_a1.onRelease = function() {// the mc click code

            if (pDown) {

            if (frame_pawn_a1 == 1) {

            pawn_a1.gotoAndStop(2);

            frame_pawn_a1 = 2;

            }

            if (frame_pawn_a1 == 3) {

            pawn_a1.gotoAndStop(4);

            frame_pawn_a1 = 4;

            }

            }

            if (cDown) {

            if (frame_pawn_a1 == 1 || frame_pawn_a1 == 2) {

            pawn_a1.gotoAndStop(3);

            frame_pawn_a1 = 3;

            }

            if (frame_pawn_a1 == 3 || frame_pawn_a1 == 4) {

            pawn_a1.gotoAndStop(1);

            frame_pawn_a1 = 1;

            }

            }

            };

            • 3. Re: Can someone please help me see my mistake?
              Ned Murphy Adobe Community Professional & MVP

              Except for a possible flaw in logic there doesn't appear to be anything in that code that would cause that error.  That type of error usually comes up when the program is running an infinite loop.  Do you have code in any frames that involves loops?

               

              The possible flaw I mention has to do with...

               

              if (frame_pawn_a1 == 1 || frame_pawn_a1 == 2) {

              pawn_a1.gotoAndStop(3);

              frame_pawn_a1 = 3; // you just turned this value into 3

              }

              if (frame_pawn_a1 == 3 || frame_pawn_a1 == 4) { // so this fires off as well

              pawn_a1.gotoAndStop(1);

              frame_pawn_a1 = 1;

              }

               

              so you end up with a bit of a conflict in where pawn_a1 needs to go.  You might intend to use and 'else' between those conditionals

              • 4. Re: Can someone please help me see my mistake?
                Celebrinborn Level 1

                That was it; that's what was causing my problem. Thanks for all the help