@ledsun blog

無味の味は佳境に入らざればすなわち知れず

TitleWindowにボタンを追加

Panelのソースを真似してcloseボタンの容量でTitleWindowのTitleBarにボタンを追加してみました。
mxmlファイルだと次のようにするタイトルバーにボタンが乗ります。

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"
	creationComplete="{onCreate()}"
	showCloseButton="true"
	>
	<mx:Script>
		<![CDATA[
			import mx.controls.Button;
			
			private var resizeButton:Button;
			
			private function onCreate():void{
				resizeButton = new Button();
				resizeButton.explicitWidth = resizeButton.explicitHeight = 16;
				resizeButton.focusEnabled = false;
				resizeButton.visible = true;
				resizeButton.enabled = enabled;
	            
				//デフォルトサイズでは0x0なのでサイズを設定します。
				resizeButton.setActualSize(
					resizeButton.getExplicitOrMeasuredWidth(),
					resizeButton.getExplicitOrMeasuredHeight());

				//closeButtonのすぐ左に配置します。
				resizeButton.move(
					unscaledWidth - x - 26 -
					resizeButton.getExplicitOrMeasuredWidth(),
					(titleBar.height -
					resizeButton.getExplicitOrMeasuredHeight()) / 2);
					
				resizeButton.owner = this;
				titleBar.addChild(resizeButton);
			}
		]]>
	</mx:Script>
</mx:TitleWindow>

でも、これだけだとresizeしたときにボタンの場所が狂います。