2004/12/04 | [我闪日记08]-画矩形及测试笔刷
类别(我闪我闪) | 评论(8) | 阅读(463) | 发表于 00:44

跟着老师学OOP,发现了自己以前很多的毛病。:(   先把今天的作业发上来,只是三个笔刷类中的一个,功能还不全面,等归类后再把注释添上。(本来答应老师要把最初的代码贴出来的,但是太烂了!嘻嘻,就放过偶这一次吧。下次再写那样烂一定贴!)

//测试笔刷Gpen类
class gx.GPen {
private var _width:Number;
private var _color:String;
private var _alpha:Number;
public function GPen(width:Number, color:String, alpha:Number) {
_width = width;
_color = color;
_alpha = alpha;
}
public function get width() {
return _width;
}
public function get color() {
return _color;
}
public function get alpha() {
return _alpha;
}
public function set width(width:Number):Void {
this._width = width;
}
public function set color(color:String):Void {
this._color = color;
}
public function set alpha(alpha:Number):Void {
this._alpha = alpha;
}
}

下面是使用笔刷画一个矩形,只做了一个GDrawRect函数,明天再把它改成类。现在去喝瓶洒,HOHO~

//插入测试笔刷GPen
import gx.GPen;
var mypen:GPen = new GPen(3, "0x0000ff", 70);
//mypen.width = 10;
//画矩形drawRect
function GDrawRect(pen:GPen, x:Number, y:Number, h:Number, w:Number) {
_root.createEmptyMovieClip("gx", 1);
with (_root.gx) {
lineStyle(pen.width, pen.color, pen.alpha);
moveTo(x, y);
lineTo(x+w, y);
lineTo(x+w, y+h);
lineTo(x, y+h);
lineTo(x, y);
}
}
//测试,画出一蓝色小矩形
GDrawRect(mypen, 100, 100, 30, 50);
 

 

0

评论Comments