Thanks Alex, good info as usual. Jason Merrill Bank of America GT&O L&LD Solutions Design & Development eTools & Multimedia
Bank of America Flash Platform Developer Community ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Alex Harui Sent: Thursday, January 24, 2008 6:07 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] chicken and egg object instatiation The debugger reads every getter function in an object that is in scope. This can cause getters to fire early before other things are set. It doesn't happen to me often, but when I run into that, I just add null tests and return null. ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Paul Andrews Sent: Thursday, January 24, 2008 3:00 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] chicken and egg object instatiation ----- Original Message ----- From: Merrill, Jason <mailto:[EMAIL PROTECTED]> To: flexcoders@yahoogroups.com <mailto:flexcoders@yahoogroups.com> Sent: Thursday, January 24, 2008 10:52 PM Subject: RE: [flexcoders] chicken and egg object instatiation Yeah, thanks, but what you've said is all the stuff I'm already doing... Well, it's about all I can suggest while debugging by proxy! The notion of a 'parent' doesn't really exist for a network, so I'm still not sure if this is really a tree. If you have no values of parentAtom that are null, then maybe you do have an unset value for id? Maybe this is a classic where your array index count is one off and the first or last value remains unset? Basic stuff, I know (bites me all the time!) Paul Jason Merrill Bank of America GT&O L&LD Solutions Design & Development eTools & Multimedia Bank of America Flash Platform Developer Community ________________________________ From: flexcoders@yahoogroups.com <mailto:flexcoders@yahoogroups.com> [mailto:[EMAIL PROTECTED] On Behalf Of Paul Andrews Sent: Thursday, January 24, 2008 5:47 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] chicken and egg object instatiation Jason, Presumably you're simplifying things. In a network diagram, there may be several other connected atoms, so you'd need an array of parentAtoms and it wouldn't be a parent relationship. If you're really talking about a tree, then the first atom won't have a parent and will be null. When you create each atom, put a reference to it in an array. When you think you've populated all the parentAtom references, check them all by cycling through the array. Somewhere, somehow, you must have a null parentAtom value. Sorry, not very helpful. Paul ----- Original Message ----- From: Merrill, Jason <mailto:[EMAIL PROTECTED]> To: flexcoders@yahoogroups.com <mailto:flexcoders@yahoogroups.com> Sent: Thursday, January 24, 2008 10:38 PM Subject: [flexcoders] chicken and egg object instatiation I have some AS3 code in Flex that creates a series of objects (class instances) based on some data. It's a network diagram being drawn dynamically. Each class instance object (I call them "atoms") extends Sprite, has an id number property set in it's constructor. Each atom instance has to reference (either directly or by the id) another "atom" class instance so it knows what object is it's "parent" (I have been careful to not actually use the keyword "parent" but use other property names like atomParent) - this is so it can draw a line to it on the screen and maintain a relationship. It's kind of a chicken and egg thing, but I thought I had it solved by creating all the "atom" object instances first, and then setting the atom's parentAtom property to another atom instance later. That works, however, FP9 Debug gives me the following error when I try and reference a property on the atom's "parent" (i.e. atom.atomParent.id) Cannot access a property or method of a null object reference. The thing I don't get is the parent property (an instance of Atom) gets set right, if I trace it on an atom instance, it shows: [object Atom] As I would expect. And the id property on each atom gets set properly when the constructor runs. I've checked the data too, all is well there. However, if I trace myAtomInstance.parentAtom.id I get null, even though the constructor should have already run on that object and set that id property. How would you normally handle a situation like this? I've tried several things, like breaking up the methods that set, create atoms, and then set the parent property to run via a timer, so the atoms are created, then the atom.atomParent is set a second later and the atom.atomParent.id property is traced a second after that, but it still comes up null. If you want the code details, I think it's too much to post here, but I could post if you would like or send offlist. Jason Merrill Bank of America GT&O L&LD Solutions Design & Development eTools & Multimedia Bank of America Flash Platform Developer Community