简体   繁体   English

Flex 4 Panel 的 controlBarContent 是动态的吗?

[英]Is Flex 4 Panel's controlBarContent dynamic?

I have a custom TitleWindow component (written in ActionScript) that extends spark.componenets.TitleWindow我有一个扩展 spark.componenets.TitleWindow 的自定义 TitleWindow 组件(用 ActionScript 编写)

I want to define some controls to be in the control bar but I don't have all controls at the creation stage.我想在控制栏中定义一些控件,但在创建阶段我没有所有控件。 Also, this custom component is the base for other components which need other controls in the control bar.此外,此自定义组件是其他需要控制栏中其他控件的组件的基础。

Is there a way to add controls to the controlBarContent in ActionScript at run time?有没有办法在运行时向 ActionScript 中的 controlBarContent 添加控件?

Maybe something like the following?也许像下面这样? (this obviously didn't work) (这显然不起作用)

controlBarContent = [];
.
.
.
controlBarContent.push(new Button());

In general, look out for一般来说,要注意

addElement()

or或者

addChild()

methods.方法。

addElement() adds other UI components as sub-elements of other components. addElement() 将其他 UI 组件添加为其他组件的子元素。

This might be of interest. 可能很有趣。 Finnaly, Adobe provides good help here: 'Working with components' .最后,Adobe 在这里提供了很好的帮助: “使用组件”

UPDATE-1更新-1

Sorry, my fault.对不起,我的错。 This works for me:这对我有用:

<s:Panel creationComplete="init();" id='p' controlBarVisible="true" >

    <s:controlBarContent>

        <!-- will show controls -->
        <s:Button label="dd">

        </s:Button>

    </s:controlBarContent>


    <fx:Script>
        <![CDATA[
            import mx.controls.Button;

            import spark.components.Button;

            private function init(): void {

                var s:spark.components.Label = new spark.components.Label();
                s.text = 'My Label';
                s.width = 200;

                var a:Array = new Array();
                a.push( s );

                p.controlBarVisible = false;
                p.controlBarContent = a;
                p.controlBarVisible = true;

                p.invalidateDisplayList();

            }

        ]]>
    </fx:Script>

</s:Panel>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM