2008年8月24日星期日

ActionScript3 代码片段1

1,自定义图形绘制填充
var param3:Number = 10;
var mapData:BitmapData = new BitmapData(param3, param3, true, 0);
var shape:Shape = new Shape;
shape.graphics.beginFill(0,0);
shape.graphics.lineStyle(1,0.5,1,true);
shape.graphics.moveTo(0, param3 / 2);
shape.graphics.lineTo(param3, param3 / 2);
shape.graphics.moveTo(param3 / 2, 0);
shape.graphics.lineTo(param3 / 2, param3);
shape.width = 10;
shape.height = 10;
shape.graphics.endFill();
mapData.draw(shape);
graphics.beginBitmapFill(mapData, new Matrix(), true);
graphics.lineStyle(1);
graphics.drawRect(100, 100, 400, 10);
graphics.endFill();

效果:


2,tweener 片段
使用的tweener为http://code.google.com/p/tweener/

public function Snippet2()
{
graphics.beginFill(0x777777);
graphics.lineStyle(2, 0x3efa0);
graphics.drawCircle(0, 0, 10);
graphics.endFill();
this.addEventListener(MouseEvent.MOUSE_OVER, this.mouseOver);
this.addEventListener(MouseEvent.MOUSE_OUT, this.mouseOut);
}
public function mouseOver(event:Event):void {
Tweener.addTween(this, { _scale:2, transition:Equations.easeOutElastic});
}

public function mouseOut(event:Event):void {
// stop the pulse, then fade in
Tweener.addTween(this, { _scale:1,alpha:0.33, transition:Equations.easeOutElastic } );
}

效果如下:

没有评论: