This sort of thing drove me batty with Flex...
I finally ended up doing all init. in createComplete methods for each child
container (ie, when a child builds itself, it initializes itself)
This means I have to sprinkle "if (child != null)..." around the parent
container
though
Another problem I ran into related to using properties (getters/setters)
in the mxml (<ns:MyComponent CoolProperty="fooby" />) :
1.) 'getters' are called before the setter
I guess this is for optimization - don't set the value if its already
set?
Anyway, it meant my 'getters' had to work with un-initialzed data
2.) 'setters' called from the mxml could fire before initialization
completes
it appears from 'trace' data that the call ordering is less then
intuative -
if I recall correctly, the exact problem was that 'set' function could
be called before the object and its children are fully initialized.
Ended up having to handle null pointers in the setters too
3.) !!! bad trace() calls are silently swallowed!
This one really bugged me - if I stuck:
trace("fooby.name: " + fooby.name)
in a function, and fooby was null - then the Trace statement failed
silently AND THE REST OF THE FUNCTION DIDN'T EXECUTE!!
It was like the exception caused the function to return...
Not exactly intuative behavior for a debugging function
Steve
On 12/1/06, Sergey Kovalyov <[EMAIL PROTECTED]> wrote:
Hi All!
I create the component using code behind technique (MXML inherited
from ActionScript class inherited from framework class, Box in my
case). The component contains children defined in MXML and has some
properties that have influence on children behavior. I call
invalidateProperties() in setters and then assign some cached values
to particular children properties in commitProperties(). Everything
works ok, until you place this component instance as a child of
navigation container, ViewStack in my case - createChildren() and
commitProperties() are called when ViewStack is created, though its
grandchildren are not created, so null pointer exception is thrown.
How to fix it?
Sergey.