package com.oxylusflash.book { import caurina.transitions.Tweener; import flash.display.Sprite; import flash.events.MouseEvent; public class BarButtonTwoStates extends BarButton { /** * Second states. */ public var normalState2:Sprite; public var overState2:Sprite; public static const FIRST_STATE:int = 1; public static const SECOND_STATE:int = 2; private var _state:int = FIRST_STATE; public function BarButtonTwoStates() { normalState2.visible = false; overState2.visible = false; overState2.alpha = 0; overState2.filters = [Global.GLOW]; this.addEventListener(MouseEvent.CLICK, clickHandler, false, 0, true); } /** * Button state: FIRST_STATE or SECOND_STATE */ public function get state():int { return _state; } public function set state(value:int):void { if (_state != value) { _state = value; normalState.visible = overState.visible = _state == FIRST_STATE; normalState2.visible = overState2.visible = !normalState.visible; } } /** * Click handler. */ private function clickHandler(e:MouseEvent):void { state = _state == FIRST_STATE ? SECOND_STATE : FIRST_STATE; } /** * Rollover/out handlers. */ override protected function rollOverHandler(e:MouseEvent):void { super.rollOverHandler(e); if (!e.buttonDown) { Tweener.addTween(overState2, { alpha: 1, base: Global.baseTween } ); } } override protected function rollOutHandler(e:MouseEvent):void { super.rollOutHandler(e); Tweener.addTween(overState2, { alpha: 0, base: Global.baseTween } ); } } }