// forked from Shazypro's GUI
package {
import flash.display.Sprite;
public class SimpleButtonExample extends Sprite {
public function SimpleButtonExample() {
var life :LifeBox = new LifeBox();
addChild(life);
}
}
}
// LifeBox Class
import flash.display.Sprite;
import flash.display.DisplayObject;
internal class LifeBox extends Sprite {
// Private variables, for use only within LifeBox
// Public variables for use to the extendee
public var container :Sprite = new Sprite();
public function LifeBox() {
var container:Sprite = GUI.drawGradRect({
"width" : 100,
"height" : 400,
"colors" : [0x3381FF, 0x2154A6],
"alphas" : [1, 0],
"radius" : 10
});
container.filters = [new GlowFilter(0x2154A6, 1.0, 10, 10, 2, 5, false, false)];
this.addChild(container);
}
}
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// GUI Class
import flash.display.*;
import flash.geom.*;
import flash.filters.*;
internal class GUI {
// Private variables
// Public variables
public function GUI() {
throw ("Use a method of GUI instead of calling it directly");
}
// Internal use only - replace an Object's properties with default props
private static function replaceObjectWithDefaults (props :Object, f :String = null) :Object {
if (!f || f === "shape") {
props.alpha = props.alpha || 1.0;
props.width = props.width || 0,
props.height = props.height || 0,
props.x = props.x || 0,
props.y = props.y || 0,
props.radius = props.radius || 0;
props.lineThick = props.lineThick || null,
props.lineColor = props.lineColor || 0x000000,
props.lineAlpha = props.lineAlpha || 1.0;
props.fillColor = props.fillColor || 0x000000,
props.fillAlpha = props.fillAlpha || 1.0,
props.colors = props.colors || [0x000000, 0xFFFFFF],
props.alphas = props.alphas || [1, 1];
}
if (f === "filter") {
props.type = props.type || "glow";
props.color = props.color || 0x000;
props.alpha = props.alpha || 1.0;
props.width = props.width || 1;
props.height = props.height || 1;
props.strength = props.strength || 2;
props.quality = props.quality || 10;
props.inner = props.inner || false;
}
return props as Object;
}
/**************************
SHAPES
**************************/
// Draw a basic rectangle.
public static function drawRect (props :Object) :Sprite {
var temp :Sprite = new Sprite();
props = replaceObjectWithDefaults(props);
// If we are given a line thickness, then proceed to give
// the new sprite a border.
if (props.lineThick) {
temp.graphics.lineStyle(props.lineThick, props.lineColor, props.lineAlpha);
}
temp.graphics.beginFill(props.fillColor, props.fillAlpha);
temp.graphics.drawRoundRect(props.x, props.y, props.width, props.height, props.radius);
temp.graphics.endFill();
temp.alpha = props.alpha;
return temp as Sprite;
}
// Draw a rectangle with a gradient
public static function drawGradRect (props :Object) :Sprite {
var temp :Sprite = new Sprite(),
matrix :Matrix = new Matrix();
props = replaceObjectWithDefaults(props);
// If we are given a line thickness, then proceed to give
// the new sprite a border.
if (props.lineThick) {
temp.graphics.lineStyle(props.lineThick, props.lineColor, props.lineAlpha);
}
matrix = new Matrix();
matrix.createGradientBox(props.width, props.height, Math.PI/2);
temp.graphics.beginGradientFill(GradientType.LINEAR, props.colors, props.alphas, [0, 255], matrix,
SpreadMethod.PAD, InterpolationMethod.LINEAR_RGB);
temp.graphics.drawRoundRect(props.x, props.y, props.width, props.height, props.radius);
temp.graphics.endFill()
return temp as Sprite;
}
}