Monday, January 3, 2011

Determine If an Object is in the Display List or not?

Determine If an Object is in the Display List or not?

stage structure is --> [stage] - [root] - [mc]



trace(mc.parent);
//output:[object MainTimeline]

if(mc.parent){
    trace(「I am in the display list」);
}
//output:I am in the display list



Related code:

Will remove the object only if and when the object is really shown.
if( this.stage != null ){
    this.parent.removeChild( this );
}

Will also remove the object, but even when the object is NOT necessarily shown.
if( someObj.contains( this ) ){
    someObj.removeChild( this );
}

No comments:

Post a Comment