Adding a ControlBar via Actionscript

For a project I am working on I was using a panel component that had a controlBar. Throughout the project I used something similar several times I decided to make a component that I could extend. Being a glutton for punishment( in this situation at least ), I decided to do it in actionscript instead of MXML. All of the sudden it became very difficult to figure out how to add a ControlBar component to the bottom of a panel. ...

Once the difficulty became apparent and I could not find any other successes online I had 2 choices to make it work quickly. My first choice would be to revert to using MXML for the basis of the component and embed the necessary actionscript in a script tag. My other choice was to not use a ControlBar at all. I chose the third option, be stubborn and figure it out.

The thought kept running through my head that it must be possible, it is ultimately done through actionscript. I tried several things, starting with adding -keep to my compile options and viewing the generated actionscript. In the end the generated actionscript helped me because a comment in the Panel.createComponentsFromDescriptors function didn't jive with it.

The Panel.createComponentsFromDescriptors comment was:

Restore the original document. Otherwise, when we re-add the child when the Panel is a custom component, the child will use the custom component as the document instead of using the document in which the child was declared.

However, the generated actionscript had this line:

mx_internal::_document = this;

So maybe, the CustomPanel.controlBar.document property should be the CustomPanel object itself. So I added that to my control bar initalization function and it worked.

private function initControlBar( ):void
{
var cBar:ControlBar = new ControlBar();
cBar.enabled = true;
cBar.document = this;

// Add stuff to the ControlBar
...

this.addChild( cBar );
}

Just make sure this is the last child in your custom panel when it gets initialized. The Panel code checks the last child to see if it is a ControlBar during initialization.
----
Daryl "Deacon" Ducharme is currently Director of Application Development for the Interactive Agency Provis Media Group, LLC which helps organizations enhance identity, connect with customers and increase productivity.