1 Reply Latest reply on Apr 23, 2009 9:31 AM by kglad

    how to do instant effects in onEnterFrame?

    shintashi Level 1

      I normally use onEnterFrame = function(){} when I want the program to check every frame for things like coordinates, collision detection, if I pushed  button, or clicked the mouse on a specific location.


      Normally when I want to make a switch, I use a boolean statement, such as

      if(conditionA == 0){effect;} or  if(conditionA == 1){effect;}

      if(conditionB == true){effect;} or  if(conditionB == false){effect;}


      or more rarely I'll create a self contained switch

      if(conditionA == -1){effect;} or if(conditionA == 1){effect;} with a variable that equals  -1 or 1 when multiplied by itself.


      I once created a 0/1 switch like the above that contains the "if(conditionA == 0){effect;} or  if(conditionA == 1){effect;}"

      set, but uses a variable = -1 multiplied by itself, then multiplied by 0.5, and added to 0.5, producing 0 & 1.


      The problem I'm running into is trying to make an effect similar to my_mc.onRelease, that only does {effect} once until the

      command is repeated. When I take commands outside of the onEnterFrame, the program no longer checks for them consistently.


      When trying to do any kind of number gain, such as if(condition){"Bob Jones Account +$500.00"} either Bob Jones account

      sits there doing nothing, or goes up by +500 every fraction of a second, or I need to create a new string for each and every possible

      gain or reduction. I have the same problem with collision detection, multiplying the fractions of a second frames by whatever number

      I have for contact.

      I've only had limited success bypassing this problem with custom keylisteners such as a modified spacebar that only works when the

      key is released.


      Is there some method I'm completely missing that allows an effect to apply "once" then when the command isn't actually being "pressed" or "colliding" it goes back to listening for the next increment? I've been having a hard time with this issue for months, and it's really limiting a lot of my programming options.

        • 1. Re: how to do instant effects in onEnterFrame?
          kglad Adobe Community Professional & MVP

          you can use the watch() function to check for some changes without repeatedly looping.  but i think you're going to need to explain exactly what you want to do if you can't see how to use the watch() function.


          for example, a command isn't pressed and a command doesn't collide.  you need to better explain what you want, if you need more help.