Creating a ControlBar container in Flex using ActionScript

by Peter deHaan on February 25, 2008

in AddChild, ControlBar

The following example shows how you can create a simple Panel container with a nested ControlBar container in Flex using ActionScript.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/02/25/creating-a-controlbar-container-in-flex-using-actionscript/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Script>
        <![CDATA[
            import mx.controls.Button;
            import mx.controls.Text;
            import mx.containers.ControlBar;
            import mx.containers.Panel;

            private var panel:Panel;
            private var cBar:ControlBar
            private var txt:Text;
            private var btn:Button;

            private function init():void {
                txt = new Text();
                txt.text = "The quick brown fox jumped over the lazy dog.";
                txt.percentWidth = 100;

                btn = new Button();
                btn.label = "Button";

                cBar = new ControlBar();
                cBar.addChild(btn);

                panel = new Panel();
                panel.title = "Panel title";
                panel.status = "status";
                panel.width = 160;
                panel.height = 140;
                panel.addChild(txt);
                panel.addChild(cBar);
                addChild(panel);
            }
        ]]>
    </mx:Script>

</mx:Application>

View source is enabled in the following example.

{ 3 comments… read them below or add one }

1 mxlsw March 29, 2008 at 1:02 pm

Good example!
I find that your examples are very clear and easy to understand for flex beginners, I like this blog! ^_^

Reply

2 Peter Arisse May 20, 2009 at 5:24 pm

Very nice again naamgenoot, i must say i just started with flex, and have learned a lot from your examples keep up the good stuff!!

Reply

3 Dante Bui July 6, 2009 at 2:19 am

Easy to know, wonderful example! I appreciate so much

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: