简体   繁体   中英

Is Flex 4 Panel's controlBarContent dynamic?

I have a custom TitleWindow component (written in ActionScript) that extends spark.componenets.TitleWindow

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?

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.

This might be of interest. Finnaly, Adobe provides good help here: 'Working with components' .

UPDATE-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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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