在下面的代码中,对myChild.bar()的调用会导致异常,因为myChild为空。 myParent是一个有效的对象。我不明白的是为什么myChild还没有创建。“新”适用于Flex创建周期?
我已阅读到创建对象序列相关的以下文件,但我不知道该如何“新”有关: http://livedocs.adobe.com/flex/3/html/help.html?content=layoutperformance_03.html
任何帮助表示赞赏!
// 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>
谢谢,但我忘了提及我不能添加“myParent”,因为它是一个弹出窗口。有没有办法将它添加为PopUp? – deux11 2010-05-26 18:47:00
PopUpManager.addPopUp(myParent,this); http://livedocs.adobe.com/flex/3/langref/mx/managers/PopUpManager.html – JeffryHouser 2010-05-26 19:30:08
我的意思是问如何使用mxml标签完成。我想初始化popUp,但不能马上显示。 – deux11 2010-05-28 01:43:28