In the following code, the call to myChild.bar() results in an exception because myChild is null. myParent is a valid object. What I don't understand is why myChild has not been created yet.
I have read the following document related to object creation sequence, but I am unsure how "new" is related: http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_03.html
Any help is appreciated!
// Main.mxml
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="created()">
<mx:Script>
<![CDATA[
public var myParent:Parent = new Parent();
public function created():void {
myParent.foo();
}
]]>
</mx:Script>
</mx:Application>
// Parent.mxml
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
<mx:Script>
<![CDATA[
public function foo():void {
myChild.bar();
}
]]>
</mx:Script>
<Child id="myChild"/>
</mx:Canvas>
// Child.mxml
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
public function bar():void {
trace("Hello World");
}
]]>
</mx:Script>
</mx:Canvas>