隐藏在ButtonBar一个按钮 [英] Hide a Button in a ButtonBar

查看:136
本文介绍了隐藏在ButtonBar一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有隐藏的按钮栏的特定按钮的任何方式。根据这个答案(和链接中的第二个答案提供)禁止在ButtonBar单个按钮我需要使用的按钮栏的getChildAt方法,但是当我这样做,我得到的自定义皮肤对象,而不是Button对象。我想知道我怎么能得到访问Button对象。

I was wondering if there is any way you hide a particular button in a ButtonBar. According to this answer (and the link provided in the second answer) Disable individual buttons in a buttonbar I need to use the getChildAt method of the ButtonBar, but when I do that I get the custom skin object and not the Button object. I was wondering how I could get access to the Button object.

谢谢!

推荐答案

在假设在你的按钮栏中所有按钮将在同一时间进行渲染,你将不再需要滚动条......

Under the assumption that all buttons in your button bar will be rendered at the same time and you won't need scrollbars...

随着星火<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/ButtonBar.html#SkinPartSummary"相对=nofollow>按钮栏,您可以直接访问外观部件来获得访问按钮。从概念上讲是这样的:

With a Spark ButtonBar, you can access the skin part directly to get access to a button. Conceptually something like this:

var button : Button = mySparkButtonBarInstance.dataGroup.getElementAt(SomeIndex);
button.visible = false; // or true
button.includeInLayout = false;  // or true

如果你的按钮栏可以使用虚拟布局,并要求滚动这是行不通的。

This won't work if your ButtonBar can make use of Virtual Layouts and requires scrolling.

编辑:这是工作code证明了这种方法:

Here is working code demonstrating this technique:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![CDATA[
            import mx.core.IVisualElement;
            protected function button1_clickHandler(event:MouseEvent):void
            {
                trace(buttonBar.dataGroup.getElementAt(0));
                var button :IVisualElement = buttonBar.dataGroup.getElementAt(0);
                button.visible = false; // or true
                button.includeInLayout = false;  // or true         }
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <s:layout>
        <s:VerticalLayout paddingLeft="20" paddingTop="20"/>
    </s:layout>

    <s:ButtonBar id="buttonBar">  
        <mx:ArrayCollection>
            <fx:String>Flash</fx:String> 
            <fx:String>Director</fx:String> 
            <fx:String>Dreamweaver</fx:String> 
            <fx:String>ColdFusion</fx:String> 
        </mx:ArrayCollection>
    </s:ButtonBar>

    <s:Button label="Remove" click="button1_clickHandler(event)" />

</s:WindowedApplication>

这篇关于隐藏在ButtonBar一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆