package com.dVyper.utils { // import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.GradientType; import flash.display.SimpleButton; import flash.display.Sprite; import flash.display.Stage; import flash.events.MouseEvent; import flash.filters.BitmapFilter; import flash.filters.BitmapFilterQuality; import flash.filters.BlurFilter; import flash.filters.DropShadowFilter; import flash.filters.GlowFilter; import flash.geom.Matrix; import flash.geom.Point; import flash.geom.Rectangle; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; import flash.text.TextFormatAlign; // public class Alert { // private static var stage:Stage = null; private static var btnWidth:int = 75 private static var btnHeight:int = 18; private static var minimumWidths:Array = new Array(150, 230, 310); // /* ALERT DIALOG OPTIONS background:String - Type of background > "none" - invisible background > "nonenotmodal" - no background and make the area behind the Alert prompt focussable > "simple - simple colour background > "blur" - blurred background "simple" style is used if background is not specified buttons:Array - An array (maximum of 3) containing the Strings of the buttons to be shown in the Alert prompt callBack:Function - The function to be called when a button on the Alert prompt has been clicked - returns the name of the button that was clicked colour:int - Main colour for the Alert promptAlpha:int - Alpha of the Alert prompt textColour:int - Colour of the text shown in the Alert dialog position:Point - Position of the Alert prompt */ public static function init(stageReference:Stage):void { stage = stageReference; } public static function show(Text:* = "Made by dVyper", ALERTOPTIONS:Object = null):void { if (stage == null) { trace("Alert class has not been initialised!"); return; } var alertOptions:AlertOptions = new AlertOptions(ALERTOPTIONS, Text); var myAlert:Sprite = new Sprite(); myAlert.addChild(createBackground(alertOptions)); myAlert.addChild(getPrompt(alertOptions)); assignListeners(myAlert, alertOptions); stage.addChild(myAlert); } // private static function assignListeners(myAlert:Sprite, alertOptions:AlertOptions):void { var promptBackground:* = myAlert.getChildAt(1); var allButtons:Array = new Array(); for (var n:int;n stage.stageHeight) { myHeight = stage.stageHeight - 20; textField.autoSize = TextFieldAutoSize.NONE; textField.height = stage.stageHeight-40; } // Create a background for the prompt var ellipseSize:int = 10; /* added stroke hinting with borderColour option */promptBackground.graphics.lineStyle(1, alertOptions.borderColour, 1, true, "none"); promptBackground.graphics.beginFill(alertOptions.colour); promptBackground.graphics.drawRoundRect(0, 0, myWidth, myHeight, ellipseSize, ellipseSize); promptBackground.graphics.endFill(); // Add the specified text to the prompt /* rounded pixel values to promote better strokes */textField.x = int( (promptBackground.width/2)-(textField.width/2) ); /* rounded pixel values to promote better strokes */textField.y = int( (promptBackground.height/2)-(textField.height/2)-10 ); // ADD SPECIFIED BUTTONS TO THE PROMPT var alertButtons:Array = new Array(); for (var n:int;n"; myTextField.htmlText = ''+Text+''; myTextField.x = (btnWidth/2)-(myTextField.width/2); return myTextField; } private static function createTextField(alertOptions:AlertOptions):TextField { var Text:String = alertOptions.text; var myTextField:TextField = new TextField(); myTextField.textColor = alertOptions.textColour; myTextField.multiline = true; myTextField.selectable = false; myTextField.autoSize = TextFieldAutoSize.CENTER; myTextField.htmlText = ''+Text+''; myTextField.x = (btnWidth/2)-(myTextField.width/2); return myTextField; } // // Helper functions //----------------------------------------------------------------- // // returns a brighter version of the specified colour private static function brightenColour(colour:int, modifier:int):int { var hex:Array = hexToRGB(colour); var red:int = keepInBounds(hex[0]+modifier); var green:int = keepInBounds(hex[1]+modifier); var blue:int = keepInBounds(hex[2]+modifier); return RGBToHex(red, green, blue); } private static function doStartDrag(event:MouseEvent):void { if (event.target is Sprite) event.currentTarget.startDrag(); } private static function doStopDrag(event:MouseEvent):void { if (event.target is Sprite) event.currentTarget.stopDrag(); } private static function hexToRGB (hex:uint):Array { var Colours:Array = new Array(); Colours.push(hex >> 16); var temp:uint = hex ^ Colours[0] << 16; Colours.push(temp >> 8); Colours.push(temp ^ Colours[1] << 8); return Colours; } private static function keepInBounds(number:int):int { if (number < 0) number = 0; if (number > 255) number = 255; return number; } private static function RGBToHex(uR:int, uG:int, uB:int):int { var uColor:uint; uColor = (uR & 255) << 16; uColor += (uG & 255) << 8; uColor += (uB & 255); return uColor; } } } import flash.geom.Point; internal class AlertOptions { // public var background:String; public var buttons:Array = new Array(); public var callback:Function; public var colour:int; /* added this option */public var borderColour:int; public var fadeIn:Boolean; public var position:Point; public var promptAlpha:Number; public var text:String; public var textColour:int = 0x000000; // public function AlertOptions(alertOptions:Object, Text:*):void { if (alertOptions != null) { if (alertOptions.background == null) { background = "simple"; } else { background = alertOptions.background; } if (alertOptions.buttons == null) { buttons = ["OK"]; } else { if (alertOptions.buttons.length > 3) { buttons = alertOptions.buttons.slice(0, 2); } else { buttons = alertOptions.buttons; } } callback = alertOptions.callback; if (alertOptions.colour == null) { colour = 0x4E7DB1; } else { colour = alertOptions.colour; } /* Added this code here */ if (alertOptions.borderColour == null) { borderColour = 0; } else { borderColour = alertOptions.borderColour; } /* end my code add */ position = alertOptions.position; if (alertOptions.promptAlpha == null) { promptAlpha = 0.9; } else { promptAlpha = alertOptions.promptAlpha; } if (alertOptions.textColour != null) { textColour = alertOptions.textColour; } else { textColour = 0x000000; } } else { background = "simple"; buttons = ["OK"]; colour = 0x4E7DB1; borderColour = 0; promptAlpha = 0.9; textColour = 0x000000; } text = Text.toString(); } }