package com.oxylusflash.book { import caurina.transitions.Tweener; import flash.display.BlendMode; import flash.display.Sprite; import flash.filters.GlowFilter; import flash.events.MouseEvent; public class BarButton extends ObjectWithTooltip { /** * Normal and over states sprites. */ public var normalState:Sprite; public var overState:Sprite; /** * Button disable alpha. */ private static const DISABLED_ALPHA:Number = 0.3; public function BarButton() { tipYOffset = -34; normalState.cacheAsBitmap = true; normalState.mouseEnabled = false; normalState.blendMode = BlendMode.LAYER; overState.cacheAsBitmap = true; overState.blendMode = BlendMode.LAYER; overState.alpha = 0; overState.filters = [Global.GLOW]; this.blendMode = BlendMode.LAYER; this.mouseChildren = false; this.hitArea = normalState; this.buttonMode = true; this.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler, false, 0, true); this.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler, false, 0, true); } /** * Rollover/out handlers. */ protected function rollOverHandler(e:MouseEvent):void { if (!e.buttonDown) { Tweener.addTween(overState, { alpha: 1, base: Global.baseTween } ); } } protected function rollOutHandler(e:MouseEvent):void { Tweener.addTween(overState, { alpha: 0, base: Global.baseTween } ); } /** * Overrides. */ override public function get width():Number { return normalState.width; } override public function set width(value:Number):void { } override public function get height():Number { return normalState.height; } override public function set height(value:Number):void { } override public function get mouseEnabled():Boolean { return super.mouseEnabled; } override public function set mouseEnabled(value:Boolean):void { if (super.mouseEnabled != value) { super.mouseEnabled = value; this.buttonMode = value; Tweener.addTween(this, { alpha: value ? 1 : DISABLED_ALPHA, base: Global.baseTween } ); } } } }