Link to home
Start Free TrialLog in
Avatar of dsrnu
dsrnu

asked on

How Do I Dynamically Delete DisplayObjects from Movie Clip?

Hi

So I have the code for creating a new object of a movie clip I have  made called listContainer. Everything on the display object side works great, they display nicely on the screen

However, when I want to delete a certain object from the stage, how would I do this?

I tried with

interestListMC.removeChildAt(#)

but it's hard to guess the numbers to deelte, since each display object produces 2 children (in my case)

is there any way to delete a certain child? by ID or something other than index? Thanks.
var listContArry:MovieClip = new listContainer();
interestListMC.addChild(listContArry);

Open in new window

Avatar of scooby_56
scooby_56
Flag of United Kingdom of Great Britain and Northern Ireland image

if you have added at design and typed in an instance name inthe properties panel,  you can remove using this
removeChild(getChildByName('box1')); //box1 is the instance name

if you added dynamically with actionscript then use the variable name
interestListMC.removeChild(listContArry); //using your variable name
Avatar of dsrnu
dsrnu

ASKER

I add the listContainer boxes dynamically, as user clicks a button

so I have code to add the listeContainer, but each listContainer is the same object name as its a for loop as in the code section

how Do I identifiy certain boxes according to their ID and delete them? I have the variable id in the obj parameter that identifies the  id of the object

would I be able to append that ID onto the listContArry variable?

Thanks!


for each(var obj:Object in interestObjArry) {
var listContArry:MovieClip = new listContainer();
interestListMC.addChild(listContArry);
listContArry.x = 25;
listContArry.y = pos_y;
pos_y += 140;
listContArry.idText.text = obj.id;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of scooby_56
scooby_56
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dsrnu

ASKER

thank you! works great
Avatar of dsrnu

ASKER

Thanks!