2 Replies Latest reply on Oct 27, 2006 5:46 AM by Newsgroup_User

    Limiting values

    Pewee2000 Level 1
      Is it possible to limit numeric values? i.e. if I was to set the arrow keys to move an object around the stage, could some code stop it from going beyond a value point. Or if I was using plus and minus keys to scale an object could I stop it from scaling
      beyond a particular value?

      Any ideas would be appreciated.
        • 1. Re: Limiting values
          Level 7
          You need a bit of simple programming logic:

          myClip._x += 10;
          if (myClip._x > 800){
          myClip._x = 800;
          }

          This would limit the referenced clip from going off the edge of the stage,
          given a stage width of 800. Normally, you should also take into account the
          clips width... etc. But this is essentially what you're looking for - add
          your movement or scaling value, then check the clip to make sure it's not
          out of your range.

          --
          Dave -
          Head Developer
          www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Limiting values
            Level 7
            > myClip._x += 10;
            > if (myClip._x > 800){
            > myClip._x = 800;
            > }

            Alternatively:

            myClip._x = Math.min((myClip._x+10), 800);



            --
            -------------------------------
            Remove '_spamkiller_' to mail
            -------------------------------