DrawingClip (com.robertpenner.display.DrawingClip)

MovieClip
        |
        +--com.robertpenner.display.DrawingClip
class DrawingClip
extends MovieClip

The DrawingClip class extends the MovieClip class adding advanced drawing utilities.

Availability:

ActionScript 2.0; Flash Player 6

Property summary

Property Description
xpen:Number

The xpen property of the DrawingClip.

ypen:Number

The ypen property of the DrawingClip.

xpenStart:Number

The xpenStart property of the DrawingClip.

ypenStart:Number

The ypenStart property of the DrawingClip.

Method summary

Method Description
init() : Void

Decorates all MovieClips with the methods of this class.

mixin(obj:Object) : Void

Decorates a particular MovieClip instance with the methods of this class.

setXPen(x:Number) : Void

Sets the x coordinate of the drawing pen.

getXPen() : Number

Returns the x coordinate of the drawing pen.

setYPen(y:Number) : Void

Sets the y coordinate of the drawing pen.

getYPen() : Number

Returns the y coordinate of the drawing pen.

getXPenStart() : Number

Returns the x coordinate of the point where a new subpath was started.

getYPenStart() : Number

Returns the y coordinate of the point where a new subpath was started.

drawLine(x1:Number, y1:Number, x2:Number, y2:Number) : Void

Draws a line between two points using the current line style.

drawTri(p1:Object, p2:Object, p3:Object) : Void

Draws a triangle defined by three corner points.

drawQuad(p1:Object, p2:Object, p3:Object, p4:Object) : Void

Draws a quadrilateral defined by four corner points.

drawRect(x1:Number, y1:Number, x2:Number, y2:Number) : Void

Draws a rectangle defined by two corner points.

drawRectRel(x:Number, y:Number, w:Number, h:Number) : Void

Draws a rectangle defined by relative coordinates, a starting point and a width and height.

drawRectCent(x:Number, y:Number, w:Number, h:Number) : Void

Draws a rectangle defined by a center point and a width and height.

drawSquare(x:Number, y:Number, w:Number) : Void

Draws a square defined by a starting point and a width.

drawSquareCent(x:Number, y:Number, w:Number) : Void

Draws a square defined by a center point and a width.

drawDot(x:Number, y:Number) : Void

Draws a one-pixel wide dot defined by a point.

drawPoly(pts:Array) : Void

Draws a polygon defined by a collection of points.

drawRegPoly(x:Number, y:Number, r:Number, numPts:Number, rotation:Number) : Void

Draws a regular polygon (a polygon with equal angles and sides).

drawOval(x:Number, y:Number, rx:Number, ry:Number) : Void

Draws an oval.

drawCircle(x:Number, y:Number, r:Number) : Void

Draws a circle.

curveThruTo(pointX:Number, pointY:Number, anchorX:Number, anchorY:Number) : Void

Draws a curve using the current line style from the current drawing position to (anchorX, anchorY) through the point that ((pointX, pointY) specifies.

drawCurve3Pts(p1:Object, p2:Object, p3:Object) : Void

Draws a curve using the current line style through the three specified points.

drawBezier(anchorX1:Number, anchorY1:Number, controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX2:Number, anchorY2:Number, tolerance:Number) : Void

Draws a cubic bezier curve using the current line style.

drawBezierPts(anchorP1:Object, controlP1:Object, controlP2:Object, anchorP2:Object, tolerance:Number) : Void

Draws a cubic bezier curve using the current line style.

curveToCubic(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number, tolerance:Number) : Void

Draws a cubic bezier curve using the current line style from the current drawing position.

curveToCubicPts(controlP1:Object, controlP2:Object, anchorP:Object, tolerance:Number) : Void

Draws a cubic bezier curve using the current line style from the current drawing position.

init() : Void

Usage


com.robertpenner.display.DrawingClip.init();

Parameters

Returns

Nothing.

Description

Decorates all MovieClips with the methods of this class.


mixin(obj:Object) : Void

Usage


com.robertpenner.display.DrawingClip.mixin(my_mc);

Parameters

obj:Object - The object to mix in.

Returns

Nothing.

Description

Decorates a particular MovieClip instance with the methods of this class.


setXPen(x:Number) : Void

Usage


my_mc.setXPen(50);

Parameters

x:Number - The x coordinate of the drawing pen.

Returns

Nothing.

Description

Sets the x coordinate of the drawing pen.


getXPen() : Number

Usage


trace (my_mc.getXPen());

Parameters

Returns

The x coordinate of the drawing pen.

Description

Returns the x coordinate of the drawing pen.


setYPen(y:Number) : Void

Usage


my_mc.setYPen(50);

Parameters

y:Number - The y coordinate of the drawing pen.

Returns

Nothing.

Description

Sets the y coordinate of the drawing pen.


getYPen() : Number

Usage


trace (my_mc.getYPen());

Parameters

Returns

The y coordinate of the drawing pen.

Description

Returns the y coordinate of the drawing pen.


getXPenStart() : Number

Usage


trace (my_mc.getXPenStart());

Parameters

Returns

The x coordinate of the point where a new subpath was started.

Description

Returns the x coordinate of the point where a new subpath was started.


getYPenStart() : Number

Usage


trace (my_mc.getYPenStart());

Parameters

Returns

The y coordinate of the point where a new subpath was started.

Description

Returns the y coordinate of the point where a new subpath was started.


drawLine(x1:Number, y1:Number, x2:Number, y2:Number) : Void

Usage


my_mc.lineStyle(4, 0x0000FF, 60);
my_mc.drawLine(0, 0, 50, 50);

Parameters

x1:Number - The x position of the first point.

y1:Number - The y position of the first point.

x2:Number - The x position of the second point.

y2:Number - The y position of the second point.

Returns

Nothing.

Description

Draws a line between two points using the current line style.


drawTri(p1:Object, p2:Object, p3:Object) : Void

Usage


my_mc.lineStyle(4, 0x0000FF, 60);
var a:Object = {x:20, y:100};
var b:Object = {x:90, y:0};
var c:Object = {x:200, y:50};
my_mc.drawTri(a, b, c);

Parameters

p1:Object - The first corner point of the triangle.

p2:Object - The second corner point of the triangle.

p3:Object - The third corner point of the triangle.

Returns

Nothing.

Description

Draws a triangle defined by three corner points.


drawQuad(p1:Object, p2:Object, p3:Object, p4:Object) : Void

Usage


my_mc.beginFill(0x00CC22, 40);
my_mc.lineStyle(2, 0x330000);
var a:Object = {x:0, y:20};
var b:Object = {x:10, y:80};
var c:Object = {x:100, y:120};
var d:Object = {x:150, y:0};
my_mc.drawQuad(a, b, c, d);
my_mc.endFill();

Parameters

p1:Object - The first corner point of the quadrilateral.

p2:Object - The second corner point of the quadrilateral.

p3:Object - The third corner point of the quadrilateral.

p4:Object - The fourth corner point of the quadrilateral.

Returns

Nothing.

Description

Draws a quadrilateral defined by four corner points.


drawRect(x1:Number, y1:Number, x2:Number, y2:Number) : Void

Usage


my_mc.beginFill(0x33DD00, 60);
my_mc.drawRect(10, 10, 240, 150);
my_mc.endFill();

Parameters

x1:Number - The x position of the first corner point.

y1:Number - The y position of the first corner point.

x2:Number - The x position of the second corner point.

y2:Number - The y position of the second corner point.

Returns

Nothing.

Description

Draws a rectangle defined by two corner points.


drawRectRel(x:Number, y:Number, w:Number, h:Number) : Void

Usage


my_mc.beginFill(0x0000FF, 40);
my_mc.drawRectRel(60, 60, 20, 30);
my_mc.endFill();

Parameters

x:Number - The x position of the starting point.

y:Number - The y position of the starting point.

w:Number - The width of the rectangle.

h:Number - The height of the rectangle.

Returns

Nothing.

Description

Draws a rectangle defined by relative coordinates, a starting point and a width and height.


drawRectCent(x:Number, y:Number, w:Number, h:Number) : Void

Usage


my_mc.lineStyle(2, 0x00FF00);
my_mc.drawRectCent(150, 100, 70, 10);

Parameters

x:Number - The x position of the center point.

y:Number - The y position of the center point.

w:Number - The width of the rectangle.

h:Number - The height of the rectangle.

Returns

Nothing.

Description

Draws a rectangle defined by a center point and a width and height.


drawSquare(x:Number, y:Number, w:Number) : Void

Usage


my_mc.lineStyle(2, 0x00FF00);
my_mc.drawSquare(250, 10, 50);

Parameters

x:Number - The x position of the starting point.

y:Number - The y position of the starting point.

w:Number - The width of the square.

Returns

Nothing.

Description

Draws a square defined by a starting point and a width.


drawSquareCent(x:Number, y:Number, w:Number) : Void

Usage


my_mc.lineStyle(2, 0x00FF00);
my_mc.drawSquare(250, 10, 50);

Parameters

x:Number - The x position of the center point.

y:Number - The y position of the center point.

w:Number - The width of the square.

Returns

Nothing.

Description

Draws a square defined by a center point and a width.


drawDot(x:Number, y:Number) : Void

Usage


my_mc.beginFill(0xFF0000);
my_mc.drawDot(130, 100);
my_mc.endFill();

Parameters

x:Number - The x position of the point.

y:Number - The y position of the point.

Returns

Nothing.

Description

Draws a one-pixel wide dot defined by a point.


drawPoly(pts:Array) : Void

Usage


var pts:Array = [];
var numPoints:Number = 50;
while (numPoints--) {
	pts.push({x:Math.random()*300, y:Math.random()*300});
}
my_mc.beginFill(0x339933);
my_mc.drawPoly(pts);
my_mc.endFill();

Parameters

pts:Array - An array of point objects, each point containing x and y properties.

Returns

Nothing.

Description

Draws a polygon defined by a collection of points.


drawRegPoly(x:Number, y:Number, r:Number, numPts:Number, rotation:Number) : Void

Usage


my_mc.beginFill(0xFF0000, 70);
my_mc.drawRegPoly(100, 100, 90, 5, 15);
my_mc.endFill();

Parameters

x:Number - The x position of the center point.

y:Number - The y position of the center point.

r:Number - The radius from the center to one of the polygon's corners.

numPts:Number - The number of points (and sides) of the polygon.

rotation:Number - The angle (in degrees) to rotate the polygon.

Returns

Nothing.

Description

Draws a regular polygon (a polygon with equal angles and sides).


drawOval(x:Number, y:Number, rx:Number, ry:Number) : Void

Usage


my_mc.beginFill(0x0000FF, 40);
my_mc.drawOval(80, 100, 50, 75);
my_mc.endFill();

Parameters

x:Number - The x position of the center point.

y:Number - The y position of the center point.

rx:Number - The horizontal radius from the center to the edge of the oval.

ry:Number - The vertical radius from the center to the edge of the oval.

Returns

Nothing.

Description

Draws an oval.


drawCircle(x:Number, y:Number, r:Number) : Void

Usage


my_mc.beginFill(0x0000FF, 40);
my_mc.drawCircle(150, 100, 50);
my_mc.endFill();

Parameters

x:Number - The x position of the center point.

y:Number - The y position of the center point.

r:Number - The radius from the center to the edge of the circle.

Returns

Nothing.

Description

Draws a circle.


curveThruTo(pointX:Number, pointY:Number, anchorX:Number, anchorY:Number) : Void

Usage


my_mc.lineStyle(4, 0x0000FF, 60);
my_mc.curveThruTo(400,50,100,200);

Parameters

pointX:Number - The x position of the curve-through point.

pointY:Number - The y position of the curve-through point.

anchorX:Number - The x position of the next anchor point.

anchorY:Number - The y position of the next anchor point.

Returns

Nothing.

Description

Draws a curve using the current line style from the current drawing position to (anchorX, anchorY) through the point that ((pointX, pointY) specifies.


drawCurve3Pts(p1:Object, p2:Object, p3:Object) : Void

Usage


this.onMouseMove = function() {
	my_mc.clear();
	my_mc.lineStyle(4, 0x0000FF, 60);
	my_mc.drawCurve3Pts({x:100, y:100}, {x:my_mc._xmouse, y:my_mc._ymouse}, {x:400, y:400});
}

Parameters

p1:Object - The first point of the curve.

p2:Object - The middle point of the curve.

p3:Object - The third point of the curve.

Returns

Nothing.

Description

Draws a curve using the current line style through the three specified points.


drawBezier(anchorX1:Number, anchorY1:Number, controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX2:Number, anchorY2:Number, tolerance:Number) : Void

Usage


my_mc.lineStyle(4, 0xFF0000, 70);
my_mc.drawBezier(0, 0, 100, 0, 0, 100, 200, 200, 2);

Parameters

anchorX1:Number - The x position of the first anchor point.

anchorY1:Number - The y position of the first anchor point.

controlX1:Number - The x position of the first control point.

controlY1:Number - The y position of the first control point.

controlX2:Number - The x position of the second control point.

controlY2:Number - The y position of the second control point.

anchorX2:Number - The x position of the second anchor point.

anchorY2:Number - The y position of the second anchor point.

tolerance:Number - The accuracy of the curve. The smaller the tolerance, the more accurate and complex the curve.

Returns

Nothing.

Description

Draws a cubic bezier curve using the current line style.


drawBezierPts(anchorP1:Object, controlP1:Object, controlP2:Object, anchorP2:Object, tolerance:Number) : Void

Usage


my_mc.lineStyle(4, 0xFF0000, 70);
var a:Object = {x:100, y:20};
var b:Object = {x:0, y:80};
var c:Object = {x:150, y:100};
var d:Object = {x:10, y:200};
my_mc.drawBezierPts(a, b, c, d, 2);

Parameters

anchorP1:Object - The first anchor point.

controlP1:Object - The first control point.

controlP2:Object - The second control point.

anchorP2:Object - The second anchor point.

tolerance:Number - The accuracy of the curve. The smaller the tolerance, the more accurate and complex the curve.

Returns

Nothing.

Description

Draws a cubic bezier curve using the current line style.


curveToCubic(controlX1:Number, controlY1:Number, controlX2:Number, controlY2:Number, anchorX:Number, anchorY:Number, tolerance:Number) : Void

Usage


my_mc.lineStyle(2, 0x33DD77);
my_mc.moveTo(60, 40);
my_mc.curveToCubic(100, 0, 0, 100, 250, 30, 2);

Parameters

controlX1:Number - The x position of the first control point.

controlY1:Number - The y position of the first control point.

controlX2:Number - The x position of the second control point.

controlY2:Number - The y position of the second control point.

anchorX:Number - The x position of the next anchor point.

anchorY:Number - The y position of the next anchor point.

tolerance:Number - The accuracy of the curve. The smaller the tolerance, the more accurate and complex the curve.

Returns

Nothing.

Description

Draws a cubic bezier curve using the current line style from the current drawing position.


curveToCubicPts(controlP1:Object, controlP2:Object, anchorP:Object, tolerance:Number) : Void

Usage


my_mc.lineStyle(4, 0x0000FF, 60);
my_mc.moveTo(60, 20);
var a:Object = {x:20, y:100};
var b:Object = {x:90, y:0};
var c:Object = {x:200, y:50};
my_mc.curveToCubicPts(a, b, c);

Parameters

controlP1:Object - The first control point.

controlP2:Object - The second control point.

anchorP:Object - The next anchor point.

tolerance:Number - The accuracy of the curve. The smaller the tolerance, the more accurate and complex the curve.

Returns

Nothing.

Description

Draws a cubic bezier curve using the current line style from the current drawing position.


xpen : Number

Usage


trace (my_mc.xpen);

Description

The xpen property of the DrawingClip.


ypen : Number

Usage


trace (my_mc.ypen);

Description

The ypen property of the DrawingClip.


xpenStart : Number

Usage


trace (my_mc.xpenStart);

Description

The xpenStart property of the DrawingClip.


ypenStart : Number

Usage


trace (my_mc.ypenStart);

Description

The ypenStart property of the DrawingClip.