フィルタ効果つきボタン

開発中に作った、簡単なカスタムコンポーネントの一例。
マウスオーバーやクリック時にGlowフィルタをかけるボタンです。
利用不可の時にはモノクロにします。
フリーのアイコンをボタンに利用する際なんかに重宝するかも。

<?xml version="1.0" encoding="utf-8"?>
<mx:Button xmlns:mx="http://www.adobe.com/2006/mxml"
  rollOver="filterByMouseEvent(event)"
  rollOut="filterByMouseEvent(event)"
  mouseDown="filterByMouseEvent(event)"
  mouseUp="filterByMouseEvent(event)">
  <mx:Script>
    <![CDATA[
      [Bindable]
      /**
       * glowEffectの色(デフォルトはグレー)
       */
      public var glowColor:uint = 0x999999;

      protected function filterByMouseEvent(e:MouseEvent):void{
        //ボタンへのフィルタをかける
        if(enabled){
          switch(e.type){
            //ロールオーバー
            case MouseEvent.ROLL_OVER:
            case MouseEvent.MOUSE_UP:
              filters = [new GlowFilter(glowColor,1)];
              break;
            //マウスダウン
            case MouseEvent.MOUSE_DOWN:
              filters = [new GlowFilter(glowColor,0.5)];
              break;
            default:
              filters = [];
              break;
          }
        }
      }

      protected override function commitProperties():void
      {
        super.commitProperties();
        if(!enabled){
          //モノクロ
          var mat:Array = [
            1/3, 1/3, 1/3, 0, 0,
            1/3, 1/3, 1/3, 0, 0,
            1/3, 1/3, 1/3, 0, 0,
            0, 0, 0, 1, 0
            ];
          filters = [new ColorMatrixFilter(mat)];
        }else{
          //とりあえず実際の動作では問題ない
          filters = [];
        }
      }
    ]]>
  </mx:Script>
</mx:Button>