How can I disable a single button in a buttonbar in Flex?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
here is the sample app.
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onComplete();"> <mx:Script> <![CDATA[ import mx.controls.Button; private function onComplete():void { for ( var i:int=0; i<btns.numChildren; i++ ) { if ( i == 0 || i % 2 == 0 ) { Button(btns.getChildAt(i)).enabled = false; } } } ]]> </mx:Script> <mx:LinkBar id="btns"> <mx:dataProvider> <mx:ArrayCollection> <mx:Array> <mx:Object label="Button 1" /> <mx:Object label="Button 2" /> <mx:Object label="Button 3" /> <mx:Object label="Button 4" /> <mx:Object label="Button 5" /> <mx:Object label="Button 6" /> </mx:Array> </mx:ArrayCollection> </mx:dataProvider> </mx:LinkBar> </mx:WindowedApplication>
Basically you access individual buttons using
libkBarInst.getChildAt(n)
which gives you a Button. Hope that helps.
回答2:
Check this post Disabling individual buttons on a Flex ButtonBar control