[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How Do I Dynamically Delete DisplayObjects from Movie Clip?

Posted on 2009-04-02
5
Medium Priority
?
599 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

829 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