package com.oxylusflash.book { import caurina.transitions.Tweener; import flash.display.BlendMode; import flash.display.Sprite; import flash.events.Event; public class FadeInOutItem extends Sprite { public static const FADE_COMPLETE:String = "fadeComplete"; public static const INVISIBLE:int = 0; public static const VISIBLE:int = 1; protected var _state:int = VISIBLE; protected var inTime:Number = Global.baseTween.time; protected var outTime:Number = Global.baseTween.time * 0.5; public function FadeInOutItem() { this.blendMode = BlendMode.LAYER; } /** * Current state: visible or invisible */ public function get state():int { return _state; } public function set state(value:int):void { if (_state != value) { _state = value; Tweener.addTween(this, { alpha: _state == VISIBLE ? 1 : 0, base: Global.baseTween, transition: _state == VISIBLE ? "easeinquart" : "easeoutquad", time: _state == VISIBLE ? inTime : outTime, onComplete: fadeCompleteHandler } ); } } protected function fadeCompleteHandler():void { this.dispatchEvent(new Event(FADE_COMPLETE)); } /** * Override alpha */ override public function get alpha():Number { return super.alpha; } override public function set alpha(value:Number):void { super.alpha = value; this.visible = value > 0; } } }