主に IT 技術を整理するためにメモ的に書き溜めています。少しだけフリーソフトもあるよ。コメントを残すには、 facebook を使ってください。

Flex で TitleWindow を resize 可能にする

最終更新日 2007-10-27 19:51:19 (1年以上前の記事です)

Flex で何かと使える TitleWindow をマウスで普通のウインドウみたいにリサイズを可能にしてみた。
そもそもなぜこのコントロールはこんなに中途半端なんだろう。クローズボタンはあるのに。

基本 MouseEvent を拾ってるだけ。
その時のソース。

ソース

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow
  xmlns:mx="http://www.adobe.com/2006/mxml"
  layout="absolute"
  title="Resizable Draggable Window"
  showCloseButton="true"
  mouseDown="onThis_mouseDown(event);"
  mouseMove="onThis_mouseMove(event);"
  mouseUp="onThis_mouseUp(event);"
  close="onThis_close();"
  creationComplete="onThis_creationComplete();"
  width="400" height="300"
>
  <mx:Script>
    <![CDATA[
      import mx.controls.Alert;
      import mx.core.Application;
      import mx.managers.PopUpManager;

      private const SIZE_DRAGAREA:int = 5;
      private const SIZE_MIN_WIDTH:int = 40;
      private const SIZE_MIN_HEIGHT:int = 30;

      private var blDragTop:Boolean = false;
      private var blDragRight:Boolean = false;
      private var blDragBottom:Boolean = false;
      private var blDragLeft:Boolean = false;
      private var iDragPosHeight:int = 0;
      private var iDragPosWidth:int = 0;

      private function onThis_creationComplete():void
      {
        // set EventListener on parent Application for mouseUp and mouseMove
        Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, onParent_mouseUp);
        Application.application.parent.addEventListener(MouseEvent.MOUSE_MOVE, onParent_mouseMove);
      }

      private function onThis_mouseDown(event:MouseEvent):void
      {
        // check Top pos
        if( event.localY < SIZE_DRAGAREA )
        {
          blDragTop = true;
          iDragPosHeight = event.localY;
        }

        // check Right pos
        if( this.width - SIZE_DRAGAREA < event.localX )
        {
          blDragRight = true;
          iDragPosWidth = this.width - event.localX;
        }

        // check Bottom pos
        if( this.height - SIZE_DRAGAREA < event.localY )
        {
          blDragBottom = true;
          iDragPosHeight = this.height - event.localY;
        }
        
        // check Left pos
        if( event.localX < SIZE_DRAGAREA )
        {
          blDragLeft = true;
          iDragPosWidth = event.localX;
        }
      }

      private function onParent_mouseMove(event:MouseEvent):void
      {
        doDrag(event.stageX, event.stageY);
      }

      private function onThis_mouseMove(event:MouseEvent):void
      {
        doDrag(event.stageX, event.stageY);
      }

      private function onParent_mouseUp(event:MouseEvent):void
      {
        outDragMode();
      }

      private function onThis_mouseUp(event:MouseEvent):void
      {
        outDragMode();
      }
      
      private function onThis_close():void
      {
        PopUpManager.removePopUp(this);
      }

      private function doDrag(intX:int, intY:int):void
      {
        if( blDragTop )
        {
          if( this.y + this.height - intY + iDragPosHeight > SIZE_MIN_HEIGHT )
          {
            this.height = this.y + this.height - intY + iDragPosHeight;
            this.y = intY - iDragPosHeight;
          }
          else
          {
            this.y = this.y + this.height - SIZE_MIN_HEIGHT;
            this.height = SIZE_MIN_HEIGHT;
          }
        }

        if( blDragRight )
        {
          if( intX - this.x + iDragPosWidth > SIZE_MIN_WIDTH )
          {
            this.width = intX - this.x + iDragPosWidth;
          }
          else
          {
            this.width = SIZE_MIN_WIDTH;
          }
        }
        
        if( blDragBottom )
        {
          if( intY - this.y + iDragPosHeight > SIZE_MIN_HEIGHT )
          {
            this.height = intY - this.y + iDragPosHeight;
          }
          else
          {
            this.height = SIZE_MIN_HEIGHT;
          }
        }
        
        if( blDragLeft )
        {
          if( this.x + this.width - intX + iDragPosWidth > SIZE_MIN_WIDTH )
          {
            this.width = this.x + this.width - intX + iDragPosWidth;
            this.x = intX - iDragPosWidth;
          }
          else
          {
            this.x = this.x + this.width - SIZE_MIN_WIDTH;
            this.width = SIZE_MIN_WIDTH;
          }
        }
      }
      
      private function outDragMode():void
      {
        blDragTop = blDragRight = blDragBottom = blDragLeft = false;
      }
    ]]>
  </mx:Script>
  
</mx:TitleWindow>

プレビュー

最終更新日 2007-10-27 19:51:19

コメント このエントリーをはてなブックマークに追加

フリーソフトウエア
EnjoiFLV
EnjoiPacket
EnjoiCrypto
ランキング
rank2, rank3, rank7, rank10, rank11
todo メモ
facebook 対応
ページ処理
RSS feed
検索機能
認証いる?
更新日表示
実はカテゴリ機能
多言語
実はユーザ機能
ソースその内公開
動作環境メモ
php-5.1.6 with PDO
SQLite-3.3
IE6
FireFox-1.5
RSS
非認証

検索
Google