4 Replies Latest reply on Jan 24, 2010 2:41 AM by MamenFLASH$

    Need Action Script Help PLEEAASEE

    lawleyscott

      I have a project that and  is a prize wheel, here is my code for starting and stopping the wheel

      if (Key.isDown(Key.ENTER))
      {
      speed=speed*.99;
          }

      else if (Key.isDown(Key.RIGHT)){
          speed=5;
      }
      else if (Key.isDown(Key.LEFT)){
          speed=0;
      }
      this._visible=true;

       

      The right and left key functions work perfect but the enter key needs to be "held down" until the wheel slowly stops. I want to be able to just press the "Enter" key and the wheel will slowly (randomly)come to a halt. the problem code is in bold. any help would be great.

        • 1. Re: Need Action Script Help PLEEAASEE
          Ned Murphy Adobe Community Professional & MVP

          Assuming you really mean you want to press and release the Enter key, what you need to do is have something else play the role of what the "if (Key.isDown(Key.ENTER))" line does for you in terms of repeatedly changing the speed value.  Something in the way of an onEnterFrame activity that gets intiated by the pressing of the Enter key, but just once... you need something to only allow it to intiate that enterFrame once...

           

          So somewhere outside that code you want to have a Boolean variable that is used when the Enter key is pressed which conditionally calls a function that initiates the enterframe activity and then sets that value to false to keep it from being called again.  That variable could be reset to true when the RIGHT key initiates a new go.  So pressing the Enter key sets that variable to true.  The code would follow along the lines of what I show below, but I cannot say it's polished stuff as shown... just the concept is attempted.  I don't know what other code you have involved in matters.

           

          var startSlowing = true;

           

          if (Key.isDown(Key.ENTER))
          {

               if(startSlowing){

                    slowItDown();

                    startSlowing = false;

              }
          }
          else if (Key.isDown(Key.RIGHT)){
              speed=5;

              if(!startSlowing ){ // means it was restarted in mid-spin

                    delete this.onEnterFrame;

               }

                startSlowing = true;
          }
          else if (Key.isDown(Key.LEFT)){
              speed=0;

              if(!startSlowing){

                    delete this.onEnterFrame;

               }

          }

           

           

          function slowItDown(){

               this.onEnterFrame = function(){

                    speed=speed*.99;

                    if(speed < someLimit){

                         delete this.onEnterFrame;

                    }

               }

          }

          • 2. Re: Need Action Script Help PLEEAASEE
            lawleyscott Level 1

            I'm not sure what you mean. I have enclosed the fa file for you to look at.

            Thanks a million

            • 3. Re: Need Action Script Help PLEEAASEE
              Ned Murphy Adobe Community Professional & MVP

              As long as you are holding the Enter key down, it is passing that condition you test it for, so it adjusts the speed value.  As soon as you let it go, it stops because the isDown is no longer true.  So you need to use code that executes in a similarly continuous manner, which enterframe event code does.  So you need to initiate that enterframe, but you only need/want to initiate it once.  That true/false variable provides that control.  If the variable is true, it allows the enterframe's function to be called, and it is immediately made false so that it will not allow it to be called again.

               

              I don't need to look at your fla, I understand what is going on.  You're the one who needs to look at things and come to an understanding about them.

              • 4. Re: Need Action Script Help PLEEAASEE
                MamenFLASH$ Level 1

                Hi. As far as I can see, you have a var named speed. Have you declared 

                the var at the beginning of the code? MamenFLASH$

                El 24/01/2010, a las 1:20, lawleyscott escribió:

                 

                >

                I have a project that and  is a prize wheel, here is my code for 

                starting and stopping the wheel

                *if (Key.isDown(Key.ENTER))

                {

                speed=speed*.99;

                    }*

                else if (Key.isDown(Key.RIGHT)){

                    speed=5;

                }

                else if (Key.isDown(Key.LEFT)){

                    speed=0;

                }

                this._visible=true;

                >

                The right and left key functions work perfect but the enter key 

                needs to be "held down" until the wheel slowly stops. I want to be 

                able to just press the "Enter" key and the wheel will slowly 

                (randomly)come to a halt. the problem code is in bold. any help 

                would be great.

                >