Skip navigation
residentevil750
Currently Being Moderated

Repeat function for duplicated movieclip Help Please

Sep 20, 2012 11:39 AM

Tags: #duplicate #movieclip

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.

 
Replies
  • Currently Being Moderated
    Sep 20, 2012 11:46 AM   in reply to residentevil750

    try

     

    reset_mc.onRelease=function(){

    waterBtn._visible=true;

         for(var j:Number=0;j<=i;j++){if(tl["fireMC"+j]){

              tl["fireMC"+j].removeMovieClip();

         }

    i=0; // <----- reset  i

    }

     
    |
    Mark as:
  • kglad
    72,253 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 20, 2012 9:10 PM   in reply to residentevil750

    you should use something like:

     

     

    var init:Boolean;

     

    if(!init){

        var i:Number=0;

    init=true;

    }

    fireBtn.onPress=function(){

    i++;

    _root.fireMC.duplicateMovieClip("fireMC"+i, i);

    }

     

    waterBtn.onRelease=function(){

                    waterBtn._visible=false;

    }

     

    waterBtn.onPress = fadeOut;

     

    function fadeOut(){

    tl.onEnterFrame = function(){

    for(var j:Number=i;j>=0;j--){

    if(tl["fireMC"+j]){

    tl["fireMC"+j]._alpha-=5;

    if(tl["fireMC"+j]._alpha<=0){

    tl["fireMC"+j].removeMovieClip();

    }

    } else {

    delete tl.onEnterFrame;

    break;

    }

    }

    }

    }

    reset_mc.onRelease=function(){

    waterBtn._visible=true;

    for(var j:Number=i;j>=0;j--){

    if(tl["fireMC"+j]){

    tl["fireMC"+j].removeMovieClip();

    } else {

    break;

    }

    }

    }

     
    |
    Mark as:
  • kglad
    72,253 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 20, 2012 2:43 PM   in reply to residentevil750

    you should still fix your code so it does not execute useless looping calculations ad infinitum.

     
    |
    Mark as:
  • kglad
    72,253 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 20, 2012 9:10 PM   in reply to residentevil750

    i assumed you had tl defined elsewhere in your code.  but, if not, use the following to ensure tl is defined:

     

    var init:Boolean;

     

    if(!init){

        var i:Number=0;

    var tl:MovieClip=this;

    init=true;

    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points