Get a specific parent

Hi everyone!

I’m trying to get a specific parent from a child. First, I get the parent into a DisplayObjectContainer:

var container:DisplayObjectContainer = child.parent;

Then, I want to check if the class’ name of this parent is “Level”, so I want to do something like this:

while ( != Level) {
    container = container.parent;

Obviously, this doesn’t work or else I wouldn’t be writing here! :stuck_out_tongue:

And if I do trace(container), it gives me [object Hero] which is inside “Level”.

Is there a way to compare a DisplayObjectContainer with… maybe a String?

Thank you!

I searched and tried stuff before posting here, but obviously I found a solution AFTER posting my question! Here’s what I tried and worked:

while (Type.getClassName(Type.getClass(container)) != "Level") {
	container = container.parent;

What do you think?

This should help you:

if(, Level) == true)

Or you can set and check the name of the object, just be sure you use a String :slight_smile: