logo

Flex: How To Add a ControlBar In A Class That Extends TitleWindow

This is one of those posts I hops save somebody the time I wasted today trying to work this out.

If you have an ActionScript class that extends the TitleWindow (or Panel for that matter) class and you want to add a ControlBar in the over-ridden createChildren function then you need to know to add a call to the createComponentsFromDescriptors() function at the end of it.

See last line of this example:

package
{
        import mx.controls.Button;
        import mx.controls.LinkButton;
        import mx.controls.TextInput;
        
        public class SaveDialog extends TitleWindow
        {
                private static var _dialog:SaveDialog;
                
                public function SaveDialog()
                {
                        super();
                }
                
                override protected function createChildren():void
                {
                        super.createChildren();
                        
                        var _titleField:TextInput = new TextInput();
                        _titleField.text="a field";
                        addChild(_titleField);  
                        
                        var buttons:ControlBar = new ControlBar();
                                                
                        var _saveButton:Button = new Button();
                        _saveButton.label="Save";                       
                        buttons.addChild(_saveButton);
                        
                        _cancelButton = new LinkButton();
                        _cancelButton.label = "Cancel";
                        buttons.addChild(_cancelButton);
                        
                        addChild(buttons);
                        
                        //have to call this at end to put control bar in right place!
                        createComponentsFromDescriptors();
                }
                
        }
}

If you don't call this function the buttons get added, just not where you'd expect them to (at the bottom and outside the Panel's main content area.

Took me hours and hours and searching and messing about today to find that out. Hopefully you found this quicker.

Comments

    • avatar
    • aaron
    • Fri 28 May 2010 08:45 AM

    nice tip, thanks!

    • avatar
    • Jon
    • Wed 2 Mar 2011 01:59 PM

    You saved me a ton of time (and pulled out hair) with this, thanks!

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Thu 27 May 2010

Share This Page

# ( ) '

Comments

The most recent comments added:

  • avatar Jon about 14 years ago
  • avatar aaron about 14 years ago

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content