『我闪网~www.5shan.com』

Categories

-=推荐开发方面的Flash新闻、教程、下载、酷站、游戏、图片等=-
首页

Links

New Comments

Counter

Calendar

[教程]《Flash编程与创意实现》- ASExtMovieClip类

Author:我闪 PublishTime:2004-12-14

//原作者:Robert Penner 
//AS2.0改写:wiyiflash
//欢迎访问:http://www.wiyiflash.com/bbs
//-------------------------------------------------------
//ASExtMovieClip类提供了增强内置MovieClip的绘图能力的功能
//使用方法:ASExtMovieClip.initialize();
//此后MovieClip类将获得由ASExtMovieClip类赋予的增强功能

class ASExtMovieClip {
static function initialize() {
var MCP = MovieClip.prototype;
MCP.f7moveTo = MCP.moveTo;
MCP.f7lineTo = MCP.lineTo;
MCP.f7clear = MCP.clear;
MCP.moveTo = function(x:Number, y:Number) {
with (this) {
f7moveTo(x, y);
_xpen = _xpenStart=x;
_ypen = _ypenStart=y;
}
};
MCP.lineTo = function(x:Number, y:Number) {
with (this) {
f7lineTo(x, y);
_xpen = x;
_ypen = y;
}
};
MCP.clear = function() {
with (this) {
f7clear();
_xpen = _ypen=_xpenStart=_ypenStart=0;
}
};
MCP.drawLine = function(x1:Number, y1:Number, x2:Number, y2:Number) {
this.moveTo(x1, y1);
this.lineTo(x2, y2);
};
MCP.drawLinePts = function(p1:Object, p2:Object) {
this.moveTo(p1.x, p1.y);
this.lineTo(p2.x, p2.y);
};
MCP.drawTri = function(p1:Object, p2:Object, p3:Object) {
with (this) {
moveTo(p1.x, p1.y);
lineTo(p2.x, p2.y);
lineTo(p3.x, p3.y);
lineTo(p1.x, p1.y);
}
};
MCP.drawQuad = function(p1:Object, p2:Object, p3:Object, p4:Object) {
with (this) {
moveTo(p1.x, p1.y);
lineTo(p2.x, p2.y);
lineTo(p3.x, p3.y);
lineTo(p4.x, p4.y);
lineTo(p1.x, p1.y);
}
};
MCP.drawRect = function(x1:Number, y1:Number, x2:Number, y2:Number) {
with (this) {
moveTo(x1, y1);
lineTo(x2, y1);
lineTo(x2, y2);
lineTo(x1, y2);
lineTo(x1, y1);
}
};
MCP.drawRectRel = function(x:Number, y:Number, w:Number, h:Number) {
this.drawRect(x, y, x+w, y+h);
};
MCP.drawRectCent = function(x:Number, y:Number, w:Number, h:Number) {
this.drawRect(x-w/2, y-h/2, x+w/2, y+h/2);
};
MCP.drawSquare = function(x:Number, y:Number, w:Number) {
this.drawRect(x, y, x+w, y+w);
};
MCP.drawSquare = function(x:Number, y:Number, w:Number) {
//比较与this.drawRectCent(x,y,w)的执行效率问题;
var r = w/2;
this.drawRect(x-r, y-r, x+r, y+r);
};
MCP.drawDot = function(x:Number, y:Number) {
this.drawRect(x-.5, y-.5, x+.5, y+.5);
};
MCP.drawPoly = function(pts:Array) {
this.moveTo(pts[0].x, pts[0].y);
var i = pts.length;
while (i--) {
this.lineTo(pts[i].x, pts[i].y);
}
};
MCP.drawRegPoly = function(x:Number, y:Number, r:Number, numPts:Number, rotation:Number) {
var angle = (rotation-90)*(Math.PI/180);
var pts = [];
var dAngle = 2*Math.PI/numPts;
var cos = Math.cos, sin = Math.sin;
this.moveTo(r*cos(angle)+x, r*sin(angle)+y);
while (numPts--) {
angle += dAngle;
this.lineTo(r*cos(angle)+x, r*sin(angle)+y);
}
};
MCP.drawOval = function(x:Number, y:Number, rx:Number, ry:Number) {
this.moveTo(x+rx, y);
this.curveTo(rx+x, 0.4142*ry+y, 0.7071*rx+x, 0.7071*ry+y);
this.curveTo(0.4142*rx+x, ry+y, x, ry+y);
this.curveTo(-0.4142*rx+x, ry+y, -0.7071*rx+x, 0.7071*ry+y);
this.curveTo(-rx+x, 0.4142*ry+y, -rx+x, y);
this.curveTo(-rx+x, -0.4142*ry+y, -0.7071*rx+x, -0.7071*ry+y);
this.curveTo(-0.4142*rx+x, -ry+y, x, -ry+y);
this.curveTo(0.4142*rx+x, -ry+y, 0.7071*rx+x, -0.7071*ry+y);
this.curveTo(rx+x, -0.4142*ry+y, rx+x, y);
};
MCP.drawCircle = function(x:Number, y:Number, r:Number) {
this.drawOval(x, y, r, r);
};
}
}

[From 维艺--Flash论坛]

分类于:我闪推荐

Comments

{CommentAuthor} at {CommentTime} | {CommentEmail} {CommentUrl} {CommentIp}
{CommentContent}
Powered by 5DBlog.com