package com.oxylusflash.book { import flash.display.BlendMode; import flash.display.DisplayObject; import flash.display.Sprite; import flash.events.MouseEvent; import flash.filters.BlurFilter; import flash.geom.Rectangle; import flash.text.TextField; public class PopupWindow extends FadeInOutItem { public var bgMc:Sprite; public var titleTxt:TextField; public var closeBtn:GenericButton; private var content:PopupWindowContent; private static const TOP:Number = 58; private static const BOTTOM:Number = 12; private static const LEFT:Number = 12; private static const RIGHT:Number = 12; private static const BLUR:Number = 8; private var blurFilter:BlurFilter = new BlurFilter(BLUR, BLUR, 3); /** * Create new popup window. * @param winTitle Window title. * @param libContent Content from the library. * @param contW Content width. * @param contH Content height. */ public function PopupWindow(winTitle:String = "", libContent:Class = null, contW:Number = 516, contH:Number = 248) { this.blendMode = BlendMode.LAYER; this.alpha = 0; _state = FadeInOutItem.INVISIBLE; bgMc.filters = [Global.SHADOW]; bgMc.cacheAsBitmap = true; closeBtn.addEventListener(MouseEvent.CLICK, closeBtn_clickHandler, false, 0, true); titleTxt.multiline = false; titleTxt.wordWrap = false; titleTxt.condenseWhite = true; titleTxt.styleSheet = Global.styleSheet; titleTxt.htmlText = winTitle; this.width = contW + LEFT + RIGHT; this.height = contH + TOP + BOTTOM; if (libContent) { content = this.addChild(new libContent) as PopupWindowContent; content.popupWindow = this; content.width = contW; content.height = contH; content.x = LEFT; content.y = TOP; content.init(); } } /** * Close button action. * @param e */ private function closeBtn_clickHandler(e:MouseEvent):void { hide(); } /** * Show popup window. */ public function show():void { Global.overlay.state = FadeInOutItem.VISIBLE; this.state = FadeInOutItem.VISIBLE; if (content) content.reset(); } /** * Hide popup window. */ public function hide():void { this.state = FadeInOutItem.INVISIBLE; Global.overlay.state = FadeInOutItem.INVISIBLE; } /** * Disable popup window. */ public function disable():void { this.mouseEnabled = false; this.mouseChildren = false; } /** * Enable popup window. */ public function enable():void { this.mouseEnabled = true; this.mouseChildren = true; } /** * Overrides. */ override public function get width():Number { return bgMc.width; } override public function set width(value:Number):void { bgMc.width = Math.round(value) closeBtn.x = bgMc.width - RIGHT - closeBtn.width; titleTxt.width = closeBtn.x - RIGHT; } override public function get height():Number { return bgMc.height; } override public function set height(value:Number):void { bgMc.height = Math.round(value); } override public function get x():Number { return super.x; } override public function set x(value:Number):void { super.x = Math.round(value); } override public function get y():Number { return super.y; } override public function set y(value:Number):void { super.y = Math.round(value); } override public function get alpha():Number { return super.alpha; } override public function set alpha(value:Number):void { super.alpha = value; blurFilter.blurX = blurFilter.blurY = (1 - value) * BLUR; this.filters = this.visible ? [blurFilter] : []; } } }