事件监听位置
先看代码吧,这是主文件
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:myCom="*"
layout="absolute" width="600" height="500" >
<mx:ToggleButtonBar id="toggleButton" dataProvider="{control}"
bottom="0" horizontalCenter="0" toggleOnClick="true" selectedIndex="-1"/>
<mx:ViewStack id="control" width="600" height="500" visible="{toggleButton.selectedIndex > -1}">
<myCom:home/>
</mx:ViewStack>
</mx:Application>
这是home.mxml
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" label="家" width="600" height="400">
</mx:Canvas>
想要的效果是,当在主文件中点击“家”按钮时,主文件可以对点击事件监听,这个监听应该在哪加
[解决办法]
试一下吧:
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="500"> <mx:Script> <![CDATA[ import mx.controls.Alert; private function itemClickHandler():void { if (control.selectedIndex == 0) { Alert.show("点击了家"); } } ]]> </mx:Script> <mx:ToggleButtonBar id="toggleButton" dataProvider="{control}" bottom="0" horizontalCenter="0" toggleOnClick="true" itemClick="itemClickHandler()" selectedIndex="-1"/> <mx:ViewStack id="control" width="600" height="500" visible="{toggleButton.selectedIndex > -1}"> <mx:Canvas label="家" width="600" height="400"> </mx:Canvas> <mx:Canvas label="学校" width="600" height="400"> </mx:Canvas> </mx:ViewStack></mx:Application>