Here is the code. Feel free to re-use it in any way you deem fit.
package com.flexceptional.components { import mx.containers.Panel; import mx.core.UIComponent; public class ExtendedPanel extends Panel { public var headerPanel:UIComponent; override protected function createChildren():void { super.createChildren(); // Add the title panel if (headerPanel) { titleBar.addChild(headerPanel); } } override protected function updateDisplayList (unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); // Position the title panel if (headerPanel) { var y:int = (titleBar.height - headerPanel.height) / 2; var x:int = this.width - headerPanel.width - 5; headerPanel.move(x, y); } } } }
Now, thanks to the convenience of MXML and the way it is compiled, we can specify our additions to the Panel header in MXML when defining the Panel.
Example:
<comp:ExtendedPanel width="100%" height="100%" title="Properties"> <comp:headerPanel> <mx:Image source="{helpIcon}" width="16" height="16" toolTip="Open help documentation in new window" useHandCursor="true" buttonMode="true" mouseChildren="false" click="propertyHelpIcon_clickHandler(event)" /> </comp:headerPanel> <!-- Panel content --> <comp:PropertiesGrid /> </comp:ExtendedPanel>
You dont need a custom Panel.
ReplyDeleteIn a normal Panel's creation complete event handler, just call this.titleBar.addChild( component );
where component is some component you declared in the mxml - and set the x, y for the child in the resize event or similar
Line 17 should have tipped you off to this...
Also should be ??
titlePanel should be headerPanel in the example
ReplyDelete