首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

事件监听位置,该怎么解决

2012-03-15 
事件监听位置先看代码吧,这是主文件?xml version1.0 encodingutf-8?mx:Application xmlns:mxht

事件监听位置
先看代码吧,这是主文件
<?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 code
<?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> 

热点排行