Thanks.
That is a better way to write the check. (Clever! you escaped from using
"null" once again LOL)
BTW I just put the "try/catch" there to demonstrate error.
-- Keith H --
www.keith-hair.net
Steven Sacks wrote:
Here's the best way to write that. No try catch required.
if (myDO && myDO.parent) myDO.parent.removeChild(myDO);
Keith H wrote:
Steven,
Maybe its just me but...
Just doing a Boolean check on DisplayObjects always put my scripts in
high risk of runtime errors.
Especially in the case of "cleanup" operations.
Sometimes I might have a function that attempts removing a
DisplayObject that has not been "added" to the stage or has already
been removed.
So I check if the "stage" property is null for almost all cases now.
var myDO:Sprite=new Sprite();
try {
//if (myDO) { //Creates runtime error
if (myDO && myDO.stage != null) {
myDO.parent.removeChild(myDO);
} } catch (e:Error) {
trace(e.message);
}
-- Keith H --
www.keith-hair.net
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders