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 



Reply via email to