如果想要控制按钮权限,单纯使用 change事件无法实现,因为这个事件发生的时候,按钮还没有被创建,所以引用时不起作用,只能在控件的complete事件中才能起作用,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ????? xmlns:s="library://ns.adobe.com/flex/spark" ????? xmlns:mx="library://ns.adobe.com/flex/mx" ????? xmlns:ns1="*" ????? width="953" height="1328" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)"> ?<fx:Script> ??<![CDATA[ ???import mx.controls.Alert; ???import mx.events.FlexEvent; ???import mx.events.IndexChangedEvent; ? ??? ???protected function seta( ):void ???{ ????// TODO Auto-generated method stub ????var a:int; ???? a=s.selectedIndex; ????if(a==0){ ?????//Alert.show('0获得焦点'); ?????this['btn1'].enabled=false; ????} ????if(a==1){ ?????//Alert.show('1获得焦点'); ?????this['btn2'].enabled=false; ????} ???} ? ??? ???protected function application1_creationCompleteHandler(event:FlexEvent):void ???{ ???? ????seta(); ???} ?????? ??]]> ?</fx:Script> ?<fx:Declarations> ??<!-- 将非可视元素(例如服务、值对象)放在此处 --> ?</fx:Declarations> ?<ns1:date1 x="645" y="68" width="200"> ?</ns1:date1> ?<ns1:reg x="130" y="-8" width="2232" height="1554"> ?</ns1:reg> ?<mx:Accordion?? id="s" x="30" y="57" width="200" height="200" > ??<s:NavigatorContent width="100%" height="100%" label="可折叠窗格 1"> ???<s:Button id="btn1" x="51" y="83" label="按钮"? creationComplete="seta();"/> ??</s:NavigatorContent> ??<s:NavigatorContent?? width="100%" height="100%" label="a"> ???<s:Button id="btn2" x="92" y="93" label="按钮" creationComplete="seta();"/> ??</s:NavigatorContent> ?</mx:Accordion> </s:Application>