5 Replies Latest reply on May 16, 2006 3:34 PM by katyjack30096

    Can you delete an OnEnterFrame from outside the function?

    katyjack30096
      I've got a an onEnterFrame that I'm using inside several movie clips - one at a time - to sync up the narration audio with the animation on the timeline. It works great if I let it run all the way through - it detects the end of the clip, deletes the onEnterFrame and callls the next clip in the series. However, you can also click a Fast Forward button to skip to the next clip and when that happens, although the next clip is loaded, the first onEnterFrame event doesn't get deleted and suddenly I have 2 onEnterFrame events running at the same time. If you click Fast Forward a few times, you've suddenly got a performance nightmare on your hands.

      I've got a separate function handling the buttons and my onEnterFrame is already unwieldy because I'm checking for so many things. What I'd like to do is have the button handler function delete the currently running onEnterFrame and then move to the next slide. Can I do that - and if so, how? Because the ways I've tried so far haven't worked.

      If that's not possible, I'd love a suggestion on how to handle this problem. I'd assume it's some sort of listener but I'm not sure where to put it.

      Thanks -
        • 1. Re: Can you delete an OnEnterFrame from outside the function?
          Level 7
          Here is a suggestion



          // Use "myMc" as the scope/object to receive the event

          myMc.onEnterFrame = function () {

          }

          // or

          function myEnterframe () {

          }

          myMc.onEnterFrame = myEnterframe



          // Code to stop onEnterFrame event

          delete myMc.onEnterFrame;

          // or

          myMc.onEnterFrame = undefined;






          "katyjack30096" <> wrote in message ...
          > I've got a an onEnterFrame that I'm using inside several movie clips - one
          > at a
          > time - to sync up the narration audio with the animation on the timeline.
          > It
          > works great if I let it run all the way through - it detects the end of
          > the
          > clip, deletes the onEnterFrame and callls the next clip in the series.
          > However, you can also click a Fast Forward button to skip to the next clip
          > and
          > when that happens, although the next clip is loaded, the first
          > onEnterFrame
          > event doesn't get deleted and suddenly I have 2 onEnterFrame events
          > running at
          > the same time. If you click Fast Forward a few times, you've suddenly got
          > a
          > performance nightmare on your hands.
          >
          > I've got a separate function handling the buttons and my onEnterFrame is
          > already unwieldy because I'm checking for so many things. What I'd like to
          > do
          > is have the button handler function delete the currently running
          > onEnterFrame
          > and then move to the next slide. Can I do that - and if so, how? Because
          > the
          > ways I've tried so far haven't worked.
          >
          > If that's not possible, I'd love a suggestion on how to handle this
          > problem.
          > I'd assume it's some sort of listener but I'm not sure where to put it.
          >
          > Thanks -
          >


          • 2. Re: Can you delete an OnEnterFrame from outside the function?
            Level 7
            > Here is a suggestion
            >
            > // Use "myMc" as the scope/object to receive the event
            >
            > myMc.onEnterFrame = function () {
            >
            > }

            I heartily second that. For clarity, the movie clip instance name
            doesn't have to be myMc ... any valid instance name will do. The difference
            here is that you're assigning a function (named or literal) to a given event
            of a MovieClip instance. Since this code goes in a frame, you obviously
            have to provide a way for the code to know which clip it belongs to --
            hence, the instance name. onClipEvent(), by contrast, is directly attached
            to the clip, so an instance name isn't necessary.

            on() and onClipEvent() are Flash 5-era mechanisms. Flash MX (aka Flash
            6) introduced the ability to handle events in the same way that other
            objects' events are handled.

            By doing it the new way (the way Steve suggests), you have the benefit
            of putting all your code into one convenient place (event handling for any
            number of movie clips can be done from the same keyframe script of a scripts
            layer), and you can turn these events on and off as you please.


            David
            stiller (at) quip (dot) net
            Dev essays: http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: Can you delete an OnEnterFrame from outside the function?
              RonnieFizz
              okay i am not a pro when it comes to actionscript but one thing i could think of this.......


              create a function for what you want to do after the on enterframe event..then after the on enterframe event you can just call that function through if an else statement meaning that automatically the onEnterFrame event would b automatically deleted

              hope i made sense....
              • 4. Re: Can you delete an OnEnterFrame from outside the function?
                Level 7
                Sorry, i couldn't quite understand.
                Would it be possible for you to display your function for the sound event
                (enterframe) and the button actions?


                "RonnieFizz" <webforumsuser@macromedia.com> wrote in message
                news:e4d2tt$9se$1@forums.macromedia.com...
                > okay i am not a pro when it comes to actionscript but one thing i could
                > think
                > of this.......
                >
                >
                > create a function for what you want to do after the on enterframe
                > event..then
                > after the on enterframe event you can just call that function through if
                > an
                > else statement meaning that automatically the onEnterFrame event would b
                > automatically deleted
                >
                > hope i made sense....
                >


                • 5. Re: Can you delete an OnEnterFrame from outside the function?
                  katyjack30096 Level 1
                  I wasn't very clear about what I was doing - I have a custom class called SlideTracker that I created to watch the movie playing and sync the sound up with the timeline and I attach SlideTracker to each movie clip that needs to be watched. I call the onEnterFrame from within the SlideTracker class like this:

                  this.onEnterFrame = function() {
                  sound syncing stuff
                  }

                  I have my button handling code in the _root timeline along with the rest of my code. However, it turns out that you can delete an onEnterFrame event from outside the function. I put this in the button handler:

                  curSlide.onEnterFrame = null;

                  and it deletes the onEnterFrame associated with curSlide and moves on to the rest of the button handling tasks.

                  Thanks to everyone for their suggestions - I learn a lot from reading this board.