PDA

View Full Version : Remove duplicate movie clips


chromalicious
08-07-2008, 06:03 PM
Follwing is the script I have used for duplicating movieclips:

while (coalcount<2) {
_root.coal.duplicateMovieClip("coall"+coalcount, coalcount);
_root["coall"+coalcount]._x = random(550);
_root["coall"+coalcount]._y = random(500);
coalcount += 1;
}

on time-up it goes to the next scene following the script:
onEnterFrame = function () {
now = getTimer()/1000;
txt = countTotal-now;
p = parseInt(txt);
res = p;
if (p == 0) {
gotoAndPlay("scene 2", 1);
}
};

Th problem is I am not being able to remove the duplicate movieclips. I have tried using the script : _root["coall"+coalcount].removeMovieClip but it doesnot work. Help pls!

Noct
08-07-2008, 09:32 PM
Welcome aboard,

I'm assuming you are setting/declaring coalcount to 0 before you run that while script?
If so, the two clips you are creating are "_root.coall0" and "_root.coall1".

After the while has run, coalcount is now equal to 2, so "_root["coall"+coalcount]" is actually saying "_root.coall2", which wouldn't be a clip you created...

Were I going to write this, I would probably do it more like this (except i wouldn't be calling root):

//Creating:
for (var coalcount:Number = 0; coalcount<2; coalcount++) {
var cMc:MovieClip = _root.coal.duplicateMovieClip("coall"+coalcount, _root.getNextHighestDepth());
cMc._x = Math.random()*550;
cMc._y = Math.random()*550;
}
//Removing:
for (var i:Number = 0; i<coalcount; i++) {
var rMc:MovieClip = _root["coall"+i];
rMc.removeMovieClip();
}