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.
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;
}
}
}
North America
Europe, Middle East and Africa
Asia Pacific