3 Replies Latest reply on Aug 21, 2010 12:34 AM by zoldol

    The best and consistent way of ending/unloading a loaded movie

    zoldol

      Hi,

      I'm about getting crazy over the inconsistency of loading and unloading movies processes. First one or two movies, ok. But after that, I always has my fingers crossed.

       

      It's a mixture or simple game and quiz movies. So I have this Main movie as the controller that control about 3 game movies and 16 quiz movies. So, I have these piece of codes in my Main movie timeline:

       

       

      onEnterFrame = function () {

      if (NextMovieOK) {

      switch (movieQNum) {

      case 0 :

      //session intro

      NextMovieOK = false;

      sessionIntro(MovieList[movieQNum]);

      break;

      case 1 :

      //session howtoplay

      NextMovieOK = false;

      sessionHowToPlay(MovieList[movieQNum]);

      break;

      case 2 :

      //session monster1

      NextMovieOK = false;

      sessionLilMonster(MovieList[movieQNum]);

      break;

      case 3 :

      //session Question1

      NextMovieOK = false;

      numQuiz = 1;

      sessionQuestion(MovieList[movieQNum]);

      break;

      case 4 :

      bla...

      bla...

      bla...

      break;

      }

      }

      }

      function nextMov() {

      clearInterval(IDInterval);

      trace("IDInterval cleared="+IDInterval);

      movieQNum += 1;

      trace("movieQnum= "+movieQNum);

      NextMovieOK = true;

      }

       

      //I do not include sessionLilMonster/ function for other session because they are almost the same code as sessionQuestion.

       

      function sessionQuestion(moviename:String) {

      //load the movie

      dep = getNextHighestDepth();

      currLo.removeMovieClip();

      currLo = createEmptyMovieClip("currLo"+dep, dep);

      loadMovie(moviename, currLo);

      //move the loaded movie behind movie frame

      BlackMovieFrame.swapDepths(currLo);

      BGBrown._visible = true;

      BGEdge._visible = true;

      trace("moviename="+moviename);

      }

       

      function EndSession(sessionMovie:MovieClip) {

      unloadMovie(sessionMovie);

      clearInterval(IDInterval);

      IDInterval = setInterval(nextMov, 300);

      trace("IDInterval set="+IDInterval);

      }

       

      -------------------------

       

      In the Quizzes movie timeline, I use the codes below to gracefully end the movie:

       

      var IntervalID:Number;

      var MoviePointer:MovieClip = this;

       

      function DelayEnding(){

      clearInterval(IntervalID);

      _root.EndSession(MoviePointer);

      }

       

      btnArrow.onPress = function() {

      clearInterval(IntervalID);

      IntervalID = setInterval(DelayEnding, 500);

      this.enabled = false;

      };

       

      ---------------------------------

       

      What I observed (from trace statements), NextMov() sometimes are not being called ( I know this because the trace statements in NextMov function was not executed) for whatever reasons and I failed to figure out why. Has it anything to do with the setinterval thing? Could it messed everything up?

       

      Thank you in advance