flex中 accordion控件只有第一个VBOX能获取到children,后面的都为空,如下代码? TestAccordion.mxml
<?xmlversion="1.0"encoding="utf-8"?><mx:Applicationxmlns:mx="http://www.adobe.com/200...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete();"
>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function onCreationComplete():void
{
this.add.addEventListener(MouseEvent.CLICK,addHandler);
this.view.addEventListener(MouseEvent.CLICK,viewHandler);
}
private function addHandler(event:MouseEvent):void
{
Alert.show("add clicked");
}
private function viewHandler(event:MouseEvent):void
{
Alert.show("view clicked");
}
]]>
</mx:Script>
<mx:Accordion width="151">
<mx:VBox id="vbox1">
<mx:LinkButton id="add" label="add" width="100%" />
</mx:VBox>
<mx:VBox id="vbox2">
<mx:LinkButton id="view" label="view" width="100%" />
</mx:VBox>
</mx:Accordion>
</mx:Application>
this.view报错,说是空对象。
Accordion难道不能这样用吗?请大家解答一下。 展开
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="onCreationComplete();"
>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function onCreationComplete():void
{
this.add.addEventListener(MouseEvent.CLICK,addHandler);
this.view.addEventListener(MouseEvent.CLICK,viewHandler);
}
private function addHandler(event:MouseEvent):void
{
Alert.show("add clicked");
}
private function viewHandler(event:MouseEvent):void
{
Alert.show("view clicked");
}
]]>
</mx:Script>
<mx:Accordion width="151">
<mx:VBox id="vbox1">
<mx:LinkButton id="add" label="add" width="100%" />
</mx:VBox>
<mx:VBox id="vbox2">
<mx:LinkButton id="view" label="view" width="100%" />
</mx:VBox>
</mx:Accordion>
</mx:Application>
this.view报错,说是空对象。
Accordion难道不能这样用吗?请大家解答一下。 展开
1个回答
展开全部
应该是生成顺序的事情,你没有点击vbox2的栏导致里面的LinkButton 没有生成所以没有对象。
private function onCreationComplete():void
{
this.add.addEventListener(MouseEvent.CLICK,addHandler);
//
}
private function addHandler(event:MouseEvent):void
{
Alert.show("add clicked");
this.view.addEventListener(MouseEvent.CLICK,viewHandler);
}
private function viewHandler(event:MouseEvent):void
{
Alert.show("view clicked");
}
这样就可以看出来原因了。所以你的监听要加在点击<mx:VBox id="vbox2">里面
private function onCreationComplete():void
{
this.add.addEventListener(MouseEvent.CLICK,addHandler);
//
}
private function addHandler(event:MouseEvent):void
{
Alert.show("add clicked");
this.view.addEventListener(MouseEvent.CLICK,viewHandler);
}
private function viewHandler(event:MouseEvent):void
{
Alert.show("view clicked");
}
这样就可以看出来原因了。所以你的监听要加在点击<mx:VBox id="vbox2">里面
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询