【AS3代码】纯代码绘制按钮
package
{
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Main extends Sprite
{
public function Main():void
{
init();
}
private function init():void
{
var a:Sprite = new Sprite(); //按钮抬起时显示状态
huitu(a,0x00ff00);
var b:Sprite = new Sprite(); //放到按钮上显示状态
huitu(b,0xff0000);
var c:Sprite = new Sprite(); //按下按钮显示状态
huitu(c,0x0000ff);
//创建按钮对象
var abc:SimpleButton = new SimpleButton(a,b,c,c);
abc.x = abc.y = 50;
this.addChild(abc);
abc.addEventListener(MouseEvent.CLICK, abcclick);
}
private function abcclick(evt:MouseEvent):void
{
trace(evt.target.data);
}
//统一调用的绘图按钮方法
private function huitu(obj:Sprite, col:uint):void
{
obj.graphics.beginFill(col);
obj.graphics.drawRect(0,0,100,100);
obj.graphics.endFill();
}
}
}
{
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Main extends Sprite
{
public function Main():void
{
init();
}
private function init():void
{
var a:Sprite = new Sprite(); //按钮抬起时显示状态
huitu(a,0x00ff00);
var b:Sprite = new Sprite(); //放到按钮上显示状态
huitu(b,0xff0000);
var c:Sprite = new Sprite(); //按下按钮显示状态
huitu(c,0x0000ff);
//创建按钮对象
var abc:SimpleButton = new SimpleButton(a,b,c,c);
abc.x = abc.y = 50;
this.addChild(abc);
abc.addEventListener(MouseEvent.CLICK, abcclick);
}
private function abcclick(evt:MouseEvent):void
{
trace(evt.target.data);
}
//统一调用的绘图按钮方法
private function huitu(obj:Sprite, col:uint):void
{
obj.graphics.beginFill(col);
obj.graphics.drawRect(0,0,100,100);
obj.graphics.endFill();
}
}
}