Yeah, thanks, but what you've said is all the stuff I'm already doing...
 

Jason Merrill 
Bank of America 
GT&O L&LD Solutions Design & Development 
eTools & Multimedia 

Bank of America Flash Platform Developer Community 



 


________________________________

        From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Andrews
        Sent: Thursday, January 24, 2008 5:47 PM
        To: [email protected]
        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: [email protected]
<mailto:[email protected]>  
                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 



                

        

         

Reply via email to