当前位置: 首页 > 前端笔记 > FLASH > as3.0 如何绘制渐变按钮
2014年22六月

as3.0 如何绘制渐变按钮

有段时间写FLash上传插件的时候,做上传按钮,一边翻书一边做,很是辛苦。项目做完以后又忘记了。周末在家有时间就做一个demo备忘一下。

里面有很多参数,不一一记录了,找到对应的方法百度一下就可以。参数可以自己调整下,就知道什么意思了。

import flash.display.SimpleButton;
import flash.text.TextField;
import flash.geom.Matrix;

function btnLabel(){
	var btn_label:TextField = new TextField();
	btn_label.defaultTextFormat = new TextFormat("微软雅黑",16,0xffffff);
	btn_label.text = "SimpleButton";
	btn_label.width = 160;
	btn_label.x = 30;
	btn_label.y = 8;
	return btn_label;
}

var up:Sprite = new Sprite();
up.graphics.lineStyle(2, 0xcccccc,1);
var fillType:String = GradientType.LINEAR;
var colors:Array = [0xff3300, 0xffff00];
var alphas:Array = [1, 0.6];
var ratios:Array = [0, 255];
var mart:Matrix = new Matrix();
mart.createGradientBox(160, 40, (90/180)*Math.PI, 0, 15);
up.graphics.beginGradientFill("linear", colors, alphas, ratios, mart);
up.graphics.drawRoundRect(0, 0, 160, 40, 10, 10);
up.graphics.endFill();
up.addChild(btnLabel());

var down:Sprite = new Sprite();
down.graphics.lineStyle(2, 0xcccccc,1);
var d_fillType:String = GradientType.LINEAR;
var d_colors:Array = [0xff6600, 0xffff00];
var d_alphas:Array = [1, 0.6];
var d_ratios:Array = [0, 255];
var d_mart:Matrix = new Matrix();
d_mart.createGradientBox(160, 40, (90/180)*Math.PI, 0, 15);
down.graphics.beginGradientFill("linear", d_colors, d_alphas, d_ratios, d_mart);
down.graphics.drawRoundRect(0, 0, 160, 40, 10, 10);
down.graphics.endFill();
down.addChild(btnLabel());


var btn = new SimpleButton();
with(btn){
	x = 60;
	y = 30;
	downState = down;
	upState = up;
	overState = down;
	hitTestState = up;
}
addChild(btn);

这里是演示Flash:点这里下载源文件

文章信息

  • 发布日期:2014年06月22日 18:11:46
  • 固定地址:http://www.estorm.cn/notes/flash/2014-06-22/as3-simplebutton-gradient.html