6 Replies Latest reply: Sep 20, 2012 9:10 PM by kglad RSS

    Repeat function for duplicated movieclip Help Please

    residentevil750 Community Member

      In my game I have a button (fireBtn) that duplicates a movieclip of a fire(s).  I also have a water button (waterBtn) that fades out the fire and removes the fire duplicate movieclip(s).   Last there is a ‘Reset’ button (reset_mc) that also removes the fire duplicate movieclip(s) and resets all the other players.  Here is the code:

       

      //Creates Fire


      fireBtn.onPress=function(){
      i++;
      _root.fireMC.duplicateMovieClip("fireMC"+i, i);
      }

       

      waterBtn.onRelease=function(){
                      waterBtn._visible=false;
      }

       

      //Fades and removes fire


      waterBtn.onPress = fadeOut;

      function fadeOut(){
      fireMC1.onEnterFrame = function(){
      if(this._alpha >= 0){
      this._alpha-=5;
      if (this._alpha>=100 || this._alpha<=0) {
      for(var j:Number=0;j<=i;j++){
      if(tl["fireMC"+j]){
      tl["fireMC"+j].removeMovieClip();
      }
      }
      }
      }}}

       

      //Also removes fire and resets waterBtn


      reset_mc.onRelease=function(){
      waterBtn._visible=true;
      for(var j:Number=0;j<=i;j++){if(tl["fireMC"+j]){
      tl["fireMC"+j].removeMovieClip();
      }
      }

       

      This works fine the first time but after using the reset button the duplicate fire created does not fade or remove.  I think it has something to do with naming of duplicate movieclips (12th line of code).  I would like the duplicated fires to always fade no matter how many times you reset but I haven’t a clue as to how make the code do that.  I hope this makes sense.  Any help would be appreciated. Thanks in advance.