Solved

test if a child exsists

Posted on 2008-06-15
5
3,560 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
5 Comments
 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
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 integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

746 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

12 Experts available now in Live!

Get 1:1 Help Now