2 Replies Latest reply on Apr 24, 2009 9:56 AM by Zadajin

    Can I create a keypress that relates to a counter?

    Zadajin

      Hello, I am relatively new to flash and my lack of knowledge in actionscript is slowing me down. Help would be greatly appreciated

       

      I am making a game that utilizes a keypress to play a movie clip. It runs perfectly but I am trying to add to the script. After twenty key presses play a different movie.

       

      In case that doesn't make sense this is a little more in depth description, The game is a boxing game and when Key "0" is pressed a movie clip plays(showing the boxer punching) that part is fine. I am trying to have it to where after Key "0" is pressed 20 times, it will que a movie clip to kick in(the boxer that is being punched will fall down). I hope this makes sense.

        • 1. Re: Can I create a keypress that relates to a counter?
          mkayyali Level 1

          Hey Zadajin,

          do yo mean something like this:

           

           

          //Start here

           

          var counter:Number = 0;

           

          var keyListener:Object = new Object();

          keyListener.onKeyDown = function() {

          var listen:Number = Key.getCode();

          if (listen == 96) {

          counter++;

          if (counter<=20) {

          ball_mc.play();

          } else {

          trace("GAME OVER");

          }

          }

          };

          Key.addListener(keyListener);

           

           

          //End here

           

          ball_mc: is a movieclip include ball movement and when you pressed 0 ( zero ) for 20 times it will alert you be Game over

          listen == 96: is the zero code in keyboard, you can trace(Key.getCode()) to know each button's code.

           

          I hope to be this useful for you, good luck

           

          preview attached

          1 person found this helpful
          • 2. Re: Can I create a keypress that relates to a counter?
            Zadajin Level 1

            Hmm that definitly seems to be on the right track. I didn't see you attached a file at first. It is currently queued and I cannot download it. I am not sure if the file has expired or what. I'm new to the forum so maybe there is some way I go about downloading the file I dont know about so if that is the case please let me know

             

            If I could have opened the file maybe it would have made more sense but at this point I have a few questions.

            Does it matter where I put this script? I am using it on the main scene on frame 1 right now(is it suppose to be on the movieclip?)

             

            I adjusted the code to fit my needs by renaming the MC and adjusting the count, but it wont play the mc or display the Game over in the output menu.

             

            stop();
            var counter:Number = 0;
            var keyListener:Object = new Object();
            keyListener.onKeyDown = function() {
            var listen:Number = Key.getCode();
            if (listen == 96) {
            counter++;
            if (counter<=5) {
            blueko.play();
            } else {
            trace("GAME OVER");
            }
            }
            };
            Key.addListener(keyListener);

             

            I think the stop doesn't make a difference it doesn't work with or without it(but I do need the stop to hold the current frame) Thank you so much for your help and sorry for my confusion