FlexのTitleWindowをリサイズ可能にする方法が各所でとりあげられています。
しかし、低スペックマシンで中身が一杯あるTitleWindowをリサイズするとマウス移動のたびに再描画が発生して激重だったりします。
そこで、代替オブジェクトを使ってMOUSE_UPイベントが来たときだけリサイズすることで、この問題を回避することを考えました。
とりあえず、代替オブジェクトを使ってリサイズするTitleWindowが下記です。(リサイズの実装は適当)
これを各所で紹介されているリサイズの実装と組み合わせれば、軽いリサイズができると思います。
<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="680" height="494"
initialize="titlewindow1_initializeHandler(event)">
<fx:Declarations>
<!-- 非ビジュアルエレメント (サービス、値オブジェクトなど) をここに配置 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.core.*;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
private var dragProxy:Sprite;
protected function titlewindow1_initializeHandler(event:FlexEvent):void
{
dragProxy = new Sprite();
this.addEventListener(CloseEvent.CLOSE, onClose);
this.systemManager.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
this.systemManager.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
this.systemManager.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
this.rawChildren.addChild(dragProxy);
}
private function onClose(event:Event):void {
PopUpManager.removePopUp(this);
}
private var dragged:Boolean = false;
private var currentRect:Rectangle = null;
private var pos:Point = null;
private function onMouseDown(event:MouseEvent):void {
dragged = true;
currentRect = this.getRect(this);
pos = new Point(currentRect.width, currentRect.height);
drawProxy();
updateLogArea();
}
private function onMouseUp(event:MouseEvent):void {
if ( dragged ) {
this.width = dragProxy.width;
this.height = dragProxy.height;
dragProxy.graphics.clear();
}
dragged = false;
}
private function onMouseMove(event:MouseEvent):void {
if ( dragged ) {
currentRect.width += event.localX - pos.x;
currentRect.height += event.localY - pos.y;
pos.x = event.localX;
pos.y = event.localY;
drawProxy();
updateLogArea();
}
}
private function drawProxy():void {
dragProxy.graphics.clear();
dragProxy.graphics.lineStyle(3, 0xff0000);
dragProxy.graphics.moveTo(currentRect.x,currentRect.y);
dragProxy.graphics.lineTo(currentRect.x + currentRect.width, currentRect.y);
dragProxy.graphics.lineTo(currentRect.x + currentRect.width, currentRect.y + currentRect.height);
dragProxy.graphics.lineTo(currentRect.x, currentRect.y + currentRect.height);
dragProxy.graphics.lineTo(currentRect.x, currentRect.y);
}
private function updateLogArea():void {
logarea.text = currentRect.toString();
logarea.text += "\ndragged:" + dragged.toString();
}
]]>
</fx:Script>
<s:TextArea id="logarea" x="49" y="63" width="209" height="277"/>
</mx:TitleWindow>