package com.oxylusflash.book { import flash.display.Sprite; import flash.geom.Point; import com.oxylusflash.utils.*; public class TimerPie extends Sprite { private var _count:int = 0; private var _color:uint = 0; private var discMc:Sprite; private var maskMc:Sprite; private static const RADIUS:Number = 5; public static const NOMRAL_COLOR:uint = 0x7B7B7B; public static const OVER_COLOR:uint = 0xA4B3F3; public static const DEFAULT_COUNT:int = 135; /** * Timer pie used for the animation of the auto-flip button * @param color Color of the pie. */ public function TimerPie(color:uint = 0x7B7B7B) { _color = color; maskMc = this.addChild(new Sprite) as Sprite; discMc = this.addChild(new Sprite) as Sprite; maskMc.x = -RADIUS; maskMc.y = -RADIUS; discMc.x = -RADIUS; discMc.y = -RADIUS; maskMc.graphics.beginFill(0); maskMc.graphics.drawCircle(0, 0, RADIUS); maskMc.graphics.endFill(); this.mouseChildren = false; this.mouseEnabled = false; this.mask = maskMc; if(!Global.xmlAutoFlip.autoStart) this.count = DEFAULT_COUNT; } /** * Current count. */ public function get count():int { return _count; } public function set count(value:int):void { if (_count != value) { _count = value; updateGfx(); } } /** * Redraw pie. */ private function updateGfx():void { discMc.graphics.clear(); if (_count > 0) { var pt:Point = new Point(RADIUS * Math.sin(_count * Global.DEG2RAD), -RADIUS * Math.cos(_count * Global.DEG2RAD)); var sgnX:int = NumberUtil.sign(pt.x); var sgnY:int = NumberUtil.sign(pt.y); discMc.graphics.beginFill(_color); discMc.graphics.moveTo(0, -RADIUS); discMc.graphics.lineTo(0, 0); discMc.graphics.lineTo(pt.x, pt.y); discMc.graphics.lineTo(sgnX * RADIUS, pt.y); discMc.graphics.lineTo(sgnX * RADIUS, RADIUS); discMc.graphics.lineTo(RADIUS, RADIUS); discMc.graphics.lineTo(RADIUS, -RADIUS); discMc.graphics.endFill(); } } } }