Solved

How Do I Dynamically Delete DisplayObjects from Movie Clip?

Posted on 2009-04-02
5
588 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:dsrnu
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:scooby_56
ID: 24052086
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
0
 

Author Comment

by:dsrnu
ID: 24052576
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

0
 
LVL 12

Accepted Solution

by:
scooby_56 earned 500 total points
ID: 24053365
Use the 'name' property

set it when creating your mc within the looop
listContArry.name = "myMovie_" + obj.id

then you can remove using getChildByName()
removeChild(getChildByName('myMovie_' + idFromSomeWhere))
0
 

Author Comment

by:dsrnu
ID: 24054064
thank you! works great
0
 

Author Closing Comment

by:dsrnu
ID: 31565701
Thanks!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question