Solved

test if a child exsists

Posted on 2008-06-15
5
3,572 Views
Last Modified: 2013-11-12
Hi All,

I need to test to see if a child exists in a object... If it does I need to remove it, currently I am just trying to remove it and I am obviously getting a stack of runtime errors complaining that the child doesn't exist

Thanks

Xavier
0
Comment
Question by:drxav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 43

Assisted Solution

by:Rob
Rob earned 20 total points
ID: 21790215
for (part in myobject) {
    trace(part);
}
0
 
LVL 4

Author Comment

by:drxav
ID: 21790275
thats not what i need.

This is my code:

if (exclusionName != "DP_TL"){
                  removeChild(DP_TL);
            }else{
                  activeDP = DP_TL;
            }

needs to be something like:

if (exclusionName != "DP_TL" && childExists(DP_TL)){
                  removeChild(DP_TL);
            }else{
                  activeDP = DP_TL;
            }

I know that "childExists()" isnt a real function but thats to give you an idea as to what i mean.
0
 
LVL 3

Accepted Solution

by:
smash_pants earned 240 total points
ID: 21790293
0
 
LVL 4

Assisted Solution

by:emphaticDigital
emphaticDigital earned 240 total points
ID: 21828103
Hello,

You could use:

//pass name as a string, set the name using the 'name' property
if (exclusionName != "DP_TL" && getChildByName("DP_TL")){

Also you can check the suspected childs 'parent' variable, which should refrence 'this':

var isChild:Boolean = DP_TL.parent == this;//depends on scope
//or
var isChild:Boolean = DP_TL.parent == (variable referencing parent clip);//safer

both of these return 'true' if it's a child, then:
if (exclusionName != "DP_TL" && isChild){

I tested all of these and they work for me.

Good luck

0
 
LVL 4

Expert Comment

by:emphaticDigital
ID: 21866626
Hello,

Thanks for giving me an assist!

Just to be sure you're clear and to help you optimize. If the following line from your accepted solution returns a reference to an object:

var box2_mc = container_mc.getChildByName("Box2_mc");

Then it's not necessary to use the 'contains()' method since the variable would be undefined if no child exists by that name.

Good luck and thanks again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The goal of the tutorial is to teach the user how to how to record live broadcast.

696 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