Icon [Flash CS5]
////////////////////////////////////////////////////////////////////////////////
// Icon [Flash CS5]
//
// [AS3.0] beginGradientFill()メソッドだ!
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1062
////////////////////////////////////////////////////////////////////////////////
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nMVR
*/
////////////////////////////////////////////////////////////////////////////////
// Icon [Flash CS5]
//
// [AS3.0] beginGradientFill()メソッドだ!
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1062
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var icon:Icon;
public function Main() {
//Wonderfl.capture_delay(1);
init();
}
private function init():void {
icon = new Icon(150);
addChild(icon);
icon.x = 232;
icon.y = 232;
icon.scale = 2;
icon.init([0xEE4455, 0x882233], "Fl", 100, 12);
}
}
}
//////////////////////////////////////////////////
// Iconクラス [CS5]
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
import flash.filters.DropShadowFilter;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.filters.GradientBevelFilter;
import flash.filters.BitmapFilterType;
class Icon extends Sprite {
private var size:uint;
private var colors:Array;
private var txt:TextField;
private static var fontType:String = "_ゴシック";
private var fontSize:uint;
private var yOffset:int;
private var _scale:Number = 1;
public function Icon(s:uint) {
size = s;
}
public function init(list:Array, t:String, s:uint, y:int = 0):void {
colors = list;
fontSize = s;
yOffset = y;
draw();
txt.text = t;
setup();
}
private function draw():void {
var base:Shape = new Shape();
addChild(base);
var alphas:Array = [1, 1];
var ratios:Array = [0, 255];
var matrix:Matrix = new Matrix();
var offset:Number = size*0.1;
matrix.createGradientBox(size, size, Math.PI*0.5, -size*0.5, -size*0.5);
base.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
base.graphics.drawRect(-size*0.5, -size*0.5, size, size);
base.graphics.endFill();
var shade:DropShadowFilter = new DropShadowFilter(4, 90, 0x000000, 0.3, 8, 8, 2, 3, false, false);
base.filters = [shade];
txt = new TextField();
addChild(txt);
txt.x = -size*0.5;
txt.y = -size*0.5 + yOffset;
txt.width = size;
txt.height = size;
txt.type = TextFieldType.DYNAMIC;
txt.selectable = false;
//txt.embedFonts = true;
//txt.antiAliasType = AntiAliasType.ADVANCED;
var tf:TextFormat = new TextFormat();
tf.font = fontType;
tf.size = fontSize;
tf.align = TextFormatAlign.CENTER;
txt.defaultTextFormat = tf;
}
private function setup():void {
var tw:uint = txt.textWidth;
var th:uint = txt.textHeight;
var char:Shape = new Shape();
addChild(char);
var tColors:Array = [0xFFAA66, 0xFF7744];
var alphas:Array = [1, 1];
var ratios:Array = [0, 255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(tw, th, Math.PI/2, -tw*0.5, -th*0.5);
char.graphics.beginGradientFill(GradientType.LINEAR, tColors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
char.graphics.drawRect(-tw*0.5, -th*0.5, tw, th);
char.graphics.endFill();
char.mask = txt;
char.cacheAsBitmap = true;
txt.cacheAsBitmap = true;
var shadow:DropShadowFilter = new DropShadowFilter(1, 45, 0xFF9966, 0.5, 2, 2, 2, 3, false, false);
char.filters = [shadow];
//var bevel:GradientBevelFilter = new GradientBevelFilter(1, 45, [0xFFFFFF, 0x000000, 0x000000], [0.5, 0, 0.5], [0, 127, 255], 2, 2, 2, 3, BitmapFilterType.OUTER, false);
//char.filters = [bevel];
}
public function get scale():Number {
return _scale;
}
public function set scale(param:Number):void {
_scale = param;
scaleX = scaleY = _scale;
}
}