2 Replies Latest reply on May 12, 2006 5:53 PM by samdl1

    Listening for the end of a movie

    samdl1 Level 1
      Hi, I have some code that loads a movieclip into an empty clip

      var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
      container.attachMovie("twdc_mc", "twdc_mc", 1, {_x:300, _y:275});

      then i want to wait until the end of the movieclip, unload it and load another in its place - all without leaving frame one of my main timeline...so my initial thought was to add this:

      function getframes(numFrames,totalFrames) {
      if (numFrames == totalFrames){
      trace("removed") //changed the return variable to this for testing
      container.twdc_mc.onEnterFrame = getframes(container.twdc_mc._currentframe,container.twdc_mc._totalframes);

      (the use of a function because i want to re-use it)

      the problem is that the if statement is parsed and evaluated to false immediately, then it moves on to the next statement without looking back despite the existance of the onEnterFrame function

      So my question is how can I listen for this event without the need to add unLoad or removeMovieClip to the end of the offending mc?

      Thankyou in advance for any replies, I'm trying hard to get to grips with "as" but Im a php boy at heart and really struggling!

        • 1. Re: Listening for the end of a movie
          blemmo Level 1
          Hi Sam,

          in AS, you can't pass parameters to an event or callback function like onEnterFrame this way. You can either pass a function reference (without brackets, otherwise the function would execute immediately and the event is undefined after that):
          container.twdc_mc.onEnterFrame = getframes;
          or define a function 'on the fly':
          container.twdc_mc.onEnterFrame = function(){
          // ...

          Since you want to use the first way, getframes() can't have any parameters, but instead it can use the scope of the event it is bound to through the 'this' keyword:
          function getframes() {
          // trace(this._totalframes);
          if (this._currentframe == this._totalframes){
          Now 'this' depends on the scope in which getframes() is called, so you can use it with the onEnterFrame event of the loaded clip:
          container.twdc_mc.onEnterFrame = getframes;
          and it will compare twdc_mc's position to it's end. Bound to another MC it would take that MC's values.

          • 2. Re: Listening for the end of a movie
            samdl1 Level 1
            blemmo you are a godsend and now my personal hero...you also accidentally sovled about fifteen other problems on other applications for me! Thankyou very much