it should be fine, but i come from a background where catching an error is not considered a sollution. its an error and you should deal with it, not a very real and potential use case
On 7/19/07, Sunil Jolly <[EMAIL PROTECTED]> wrote:
If you use the try, catch method that shouldn't be a problem. ------------------- try { removeChild(myObject); } catch (e:Error) { //object doesn't exist as a child, do nothing } --------------------- That should fail unless myObject has been added to the stage. Or am I missing something here? Sunil -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Johannes Nel Sent: 19 July 2007 15:40 To: flashcoders@chattyfig.figleaf.com Subject: Re: [Flashcoders] Object Detection AS3 the problem with your approach is that if the object does exist but is not on the display tree it will fail On 7/19/07, Sunil Jolly <[EMAIL PROTECTED]> wrote: > > > This works for me: > > ----------------------------- > > var myObject:Object; > > if (myObject) { > removeChild(myObject); > } > > ------------------------------- > > Another method would be to catch the error: > > ----------------------------- > > try { > removeChild(myObject); > } catch (e:Error) { > //do nothing > } > > ------------------------------ > > Or you can compare it to "null": > > ------------------------------ > > if (myObject != null) { > removeChild(myObject); > } > > ------------------------------ > > Sunil > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Michael > Trim > Sent: 19 July 2007 13:58 > To: flashcoders@chattyfig.figleaf.com > Subject: [Flashcoders] Object Detection AS3 > > Hi Flashcoders, > > Learning AS3 in the deep end at the moment, so excuse the questions if > too newb for this list. > > In AS2 I may have done something like the following. > > _1___________________________________ > > if(myObject){ > > myObject.removeMovieClip(); > > } > > this.attachMovie("MyObject","myObject",1); > _____________________________________ > > > What would similar code look like in AS3? As > > > _2____________________________________ > > removeChild(myObject); > _____________________________________ > > fails if myObject doesn't exist yet as does > > > _3___________________________________ > > if(myObject) > _____________________________________ > > Which I don't think you can do anyway? > > It's the last one I'm really interested in, how do you detect if > something exists? > > Thanks > > Michael > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > -- j:pn http://www.memorphic.com/news/ _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
-- j:pn http://www.memorphic.com/news/ _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com