4 Replies Latest reply on Oct 9, 2008 11:53 AM by graphicsense

    onEnterframe Question

    graphicsense
      hi there,

      i'm not a great actionscripter and i'm having a relatively simple problem using onEnterframe with as2.0

      i've created a photo scroller which uses buttons to advance to either the next or previous photo. it functions perfectly with the actionscript i've set up, but it shifts the photos to their new x_value without any tween or animation. it just pops into place. i'd like to add a motion tween. here's the code used on the 'next photo' button i created...

      on (release) {
      headshot_1.onEnterFrame = function() {
      this._x += -267; headshot_1.onEnterFrame = null;}
      }

      how do i make the headshot_1 movie clip slide (motion tween) into place rather than just shifting it? any help would be appreciated.

      thx!
      tim
        • 1. Re: onEnterframe Question
          Rothrock Level 5
          headshot_1.onEnterFrame=function(){
          this._x-=3;
          if(this._x<=-267){
          this._x=-267;
          delete this.onEnterFrame;
          }

          Or something like that. Basically you start the onEnterFrame — which is poorly name, really it means "Do this repeatedly at the frame rate." -- make small changes each time, check to see if your condition has been met and if so delete the onEnterFrame.

          Currently, there is no difference in effect than:

          on(release){
          headshot_1._x=-267
          }

          If you don't need to do something repeatedly, then you generally don't need onEnterFrame.

          However it is a bit ironic that you are using on(release). This is an old style of coding that went out of fashion with Flash 6.

          Assuming you've given your 'next photo' button an instance name you could use code like this on the timeline which will allow you to keep all your code in one place.

          nextButton.onRelease=function(){
          headShot_1.onEnterFrame=function(){
          var dx:Number=-267-this._x
          if(Math.abs(dx)<1){
          this._x=-267;
          delete this.onEnterFrame;
          } else {
          this._x+=dx/2
          }
          }


          • 2. Re: onEnterframe Question
            Level 7
            >>which is poorly name,
            >>really it means "Do this repeatedly at the frame rate."

            Exactly... seems to be the perfect name to me. Think of it in the context of
            the play head generating events (which it is) - it enters a frame, does
            stuff, and leaves.

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


            • 3. Re: onEnterframe Question
              Rothrock Level 5
              It is a fine name if you get the event model and especially once you are a little bit used to Flash, but for newbies it can be a little confusing.

              The name tends to get people thinking it is the only way to do something when your playhead enters A (one) frame. Hence the common usages where people wrap a simple statement that could have just lived on the timeline inside of an onEnterFrame.

              Also, while the even does occur at the start of each frame its name leads to questions such as, "Where is onExitFrame." Usually so they can do something before the next frame. True this is due to not understanding how Flash works, but I don't think something so central to using AS well should be that mysterious.

              Also the name is confusing since a lot of Flash files only have one frame on the timeline. So, "Enter what frame, my timeline is stopped()." Even what you mention doesn't quite make sense, "...in the context of the play head generating events..." But if you issue a gotoAndStop() the play head is stopped so how can it continue to enter a frame and raise an event?

              There is nothing in the onEnterFrame to suggest the repeating nature of this event or that it continues even when you only have one frame. To my mind a better name would have been onFrameRate or onFPS or something like that.

              Anyways, the name is what it is and we are stuck with it.