Solved

How Do I Dynamically Delete DisplayObjects from Movie Clip?

Posted on 2009-04-02
5
587 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
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 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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now