Remove duplicate movieclips problem
i have shooter game duplicate bullet holes in wall. works nicely though have use version: flash player 6 code work. here simple code:
hit1.onpress=function(){
i++;
_root.bullet.duplicatemovieclip("bulletnew", i);
}
i have reset button use remove duplicate "bulletnew" movieclips @ once. have far removes 1 duplicate @ time:
reset_mc.onrelease=function(){
removemovieclip("bulletnew");
}
please clear instructions because have never grasped well.
thanks.
to publish later fp versions, initialize variables (like i) , check upper/lower case of code.
var i:number=0;
var tl:movieclip=this;
hit1.onpress=function(){
i++;
_root.bullet.duplicatemovieclip("bulletnew"+i, i);
}
reset_mc.onrelease=function(){
for(var j:number=0;j<i;j++){
if(tl["bulletnew"+i]){
tl["bulletnew"+i].removemovieclip();
}
}
}
p.s. if that's place create bullet holes, can make code more efficient looping through movieclips exist. example:
var i:number=0;
var bulletnewa:array=[];
hit1.onpress=function(){
bulletnewa.push(_root.bullet.duplicatemovieclip("whatever",i));
}
reset_mc.onrelease=function(){
for(var j:number=bulletnewa.length-1;j>=0;j--){
var mc:movieclip=bulletnewa.splice(j,1)[0];
mc.removemovieclip();
}
}
More discussions in ActionScript 1 and 2
adobe
Comments
Post a Comment