Ugh, then you go and use an if statement without brackets, and on the same
line to boot! I for one, would not want to maintain your code.

This is in jest of course. I am not going to say doing things "shorthand" is
wrong, but there are some very valid merits to not doing the "shorthand"
methods.

On Mon, Aug 17, 2009 at 6:58 PM, Steven Sacks <flash...@stevensacks.net>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

Reply via email to