Almost from very begining of me development Flash apps I hated to be tied to frames, movieclips, tweens and other rubbish stuff that makes any Flash programmers life a living hell when it comes to apps larger than trace("Hello World").
Theses classes are final code from many years writing AS only sites.
Actionscript Drawing Classes are designed in a way to let users to get most
out of Flash drawing API while keeping things simple and clear as possible.
Polygon class and any other class extending it should be
served with safeMode property in order to deal with situations when corner
radius is larger than corner size, which makes curves to overlap and look
ugly.
This is a top level class extended by all drawing instances
which holds all common functionality.
You can not use this class in a direct way or at least there is no point of
doing so. This class is important because all methods and properties are inherited
by sub classes.
This class provides some key features like manipulating MovieClip properties,
generation of of fills and lines.
Public properties:
Property
Description
mc:MovieClip
Read only reference to drawing object host MovieClip.
x:Number
Read/write reference to host movieclip _x property.
y:Number
Read/write reference to host movieclip _y property.
autoClear:Boolean
Boolean value indicating whether previous drawings should be clear
on each draw attempt.
Set this property to false if you want to use single drawing object
to draw several shapes, otherwise all previous drawings will be clear
before drawing new one.
Default value for this property is true.
rotation:Number
Property indicating rotation in degrees for next drawing attempt.
Different drawing objects might have different rotation center point.
For instance com.jR.Drawing.Ellipse will rotate from
center of object, com.jR.Drawing.Rectangle will rotate
at top left corner. At this stage those issues still might change.
skewX:Number
X skew property of drawing object. Valid values are in a range from
-90 to 90 degrees.
Not all drawing objects pay attention to this setting, for instance
com.jR.Drawing.Ellipse ignores skewX and skewY
because exactly the same results can be achieved by setting radiusX,
radiusY and rotation. Therefore including
skewing support would only make bigger mess with no gain.
skewY:Number
Y skew property of drawing object. Valid values are in a range from
-90 to 90 degrees.
lineSize:Number
Line size in pixels. This is same value that goes for MovieClip.lineStyle();
first argument.
Set this value to null in order to disable any line.
lineRgb:Number
Line color hex value.
lineAlpha:Number
Line alpha value within range from 0-100. Default value is null
which is translated to 100, set any numeric value to define exact line
alpha.
fillRgb:Number
Drawing fill color hex value.
This property effects only drawSolid() function.
fillAlpha:Number
Solid fill alpha value within range from 0-100. Default value is null
which is translated to 100, set any numeric value to define exact fill
alpha.
This property effects only drawSolid() function.
gradientType:String
Property indicating gradient fill type. Available values are limited
to lineal and radial. Default value is linear.
gradientColors:Array
Array of color values to be used with gradient fills. This is only
value that is a must if you want to make gradient fills. All other gradientFill
values can be and will be generated in case you haven't provided any
valid value except this one.
gradientAlphas:Array
Array of gradient fill alpha values. This array length should be equal
to length of gradientColors array. If you don't provide any
value for this property before calling drawGradient() method,
empty value will be replaced by auto generated array with same length
as gradientColors array with all values equal to 100.
gradientRatios:Array
Array of gradient fill alpha values. This array length should be equal
to length of gradientColors array. If you don't provide any
value for this property before calling drawGradient() method,
empty value will be replaced by auto generated array spreading all gradient
colors equally.
gradientMatrix_x:Number
Gradient fill x position according to host movie clip registration
point.
If no value is set auto generated value will be used which can be a
little different for each drawing class.
gradientMatrix_y:Number
Gradient fill y position according to host movieclip registration
point.
gradientMatrix_w:Number
Gradient fill width.
gradientMatrix_h:Number
Gradient fill height.
gradientMatrix_r:Number
Gradient fill rotation in degrees.
gradientX:Number
Read only auto generated gradient fill x property.
gradientY:Number
Read only auto generated gradient fill y property.
Shorthand function to set all three line properties within one call.
Call this function with no parameters to reset line style to initial state.
clear(Void):Void
Clear all drawings made by drawing object.
reset(Void):Void
Resets all values back to default state.
initMouseEvents(pointer:Boolean):Void
Call this function if you want drawing object to respond to mouse
events.
Parameter pointer corresponds to useHandCursor value
of MovieClip representing class on a stage.
After this function is called drawing object starts to broadcast when
ever any mouse event is fired.
Events that are broadcasted are listed here:
onDragOutDraw
onDragOverDraw
onPressDraw
onReleaseDraw
onReleaseOutsideDraw
onRollOutDraw
onRollOverDraw
You can subscribe to those events by using instance.addListner()
or instance.addEventListener() both of them will broadcast
message with single parameter reference to current instance.
class com.jR.Drawing.Ellipse extends com.jR.Drawing.Base
This class enables creation of ellipses and circles.
*Since this class is extending com.jR.Drawing.Base it is inheriting all
properties and methods of that class.
Usage: Drawing outline
import com.jR.Drawing.Ellipse;
var myEllipse:Ellipse = new Ellipse(_root, 1); // this will create instance at _root's level 1;
myEllipse.autoClear = false; //set this value to false in order to enable several drawings with one object
myEllipse.radius = 50; //set radius to 50 pixels
myEllipse.drawOutline({drawX:100, drawY:100}); //draw fist object at 100, 100. This will be a circle
myEllipse.drawY += 15; // move it by 15 pixels lower
myEllipse.drawOutline({radiusY:35}); //change circle into ellipse, now it's width stays at 50px while height is 35px
myEllipse.drawY += 20;
myEllipse.drawOutline({radiusY:15});
The script above will produce this:
Drawing solid filled Ellipse sector
import com.jR.Drawing.Ellipse;
var myEllipse:Ellipse = new Ellipse(_root, 1); // this will create instance at _root's level 1;
myEllipse.radiusX = 50; //set radius X to 50 pixels
myEllipse.radiusY = 40; //set radius Y to 40 pixels
myEllipse.drawX = 52; //place drawings x at 52
myEllipse.drawY = 42; //place drawings x at 42
myEllipse.startAngle = 30; //Set start angle to 30 degrees
myEllipse.endAngle = -30; //Set end angle to -30 degrees
myEllipse.fillRgb = 0x123456; // Set fill color to 0x123456
myEllipse.fillAlpha = 50; // and fillAlpha to 50 %
myEllipse.lineStyle(3, 0xFF0000, 50); // Set 3 pixel red line with 50% alpha
All properties of Ellipse object can be set through direct access like ellipseInstance.property
= value or through parameter of drawOutline(), drawSolid()
or drawGradient();
Effect will be completely the same.
Public properties:
Property
Description
radiusX:Number
Ellipse width in pixels
radiusY:Number
Ellipse height in pixels
radius:Number
Shorthand property for setting same value for radiusX and radiusY
(that would make a circle)
innerRadius:Number
Size of inner radius. This property enables you to create ring or
donut like drawing.
This value is compared to radiusX, height of inner circle will
be calculated according to radiusX/innerRadius ratio.
startAngle:Number
Start angle for circle/ellipse sector
endAngle:Number
End angle for circle/ellipse sector
showOuterLine:Boolean
Read/write property indicating whether outline should be shown.
showInnerLine:Boolean
Read/write property indicating whether outline should be shown.
This value will have no effect if no innerRadius is set.
joinLines:Boolean
Read/write property indicating whether outer and inner circle should
be joined with visible line.
drawX:Number
X position of drawing according to MovieClip registration point. This
value is representing the center of Ellipse.
drawY:Number
Y position of drawing according to MovieClip registration point.
Public methods:
Method
Description
Ellipse(host:MovieClip, level:Number)
Constructor function for new Ellipse instance.
Argument host defines parent clip that should host Ellipse
instance. level is optional argument, if it's not provided host.getNextHighestDepth()
will be used instead. Make sure you provide this argument in case you
have v2 components in application there's been issues with getNextHighestDepth
in case they're used.
drawOutline(__props:Object):Void
This function will draw outline of object with no fill. If no lineSize
value is set thickness of 1 pixel will be used.
The only optional argument __props is supposed to be an object
containing all necessary values in form {instanceProperty:value}
drawSolid(__props:Object):Void
This function will draw object with solid fill . If no lineRgb
value is set 0x0 will be used instead.
Properties used for this method are fillRgb, fillAlpha and
line style values.
The only optional argument __props is supposed to be an object
containing all necessary values in form {instanceProperty:value}
drawGradient(__props:Object):Void
This function will draw object with gradient fill .
This method will halt if no gradientColors is set, all other
gradient fill properties can be generated.
See com.jR.Drawing.Base for gradient fill properties
The only optional argument __props is supposed to be an object
containing all necessary values in form {instanceProperty:value}
class com.jR.Drawing.Polygon extends com.jR.Drawing.Base
This class can be used for creating objects with any number of control points
even curved lines and sine curves. Most common implementations of this class
is described in com.jR.Drawing.Rectangle and com.jR.Drawing.Triangle.
*Since this class is extending com.jR.Drawing.Base it is inheriting all
properties and methods of that class.
Usage: A small demo of what this class is capable of *If distance between points is smaller than point radius curve will screw.
I know about this and I plan to make auto correction for this.
X position of drawing according to MovieClip registration point.
drawY:Number
Y position of drawing according to MovieClip registration point.
roundCorners:Boolean
Property indicating whether round corners are to be used.
If this property is set to true round corners are made from circle sector,
otherwise bezzier curve is used.
passAnchors:Boolean
This value has no effect unless roundCorners is set to true.
When this property is true line is calculated to go through control
point. If roundCorners is set to false anchors are
used only as marks for bezzier curve control point.
join:Boolean
Property indicating whether last point should be joined with first
one.
showLine:Boolean
Show or not to show line around Pentagon.
points:Array
Array holding values of all control points of pentagon. Points are
described in a form{x:Number, y:Number, r:Number} where x and y are
coordinates according to MovieClip registration point or drawX
and drawY, r is corner radius in pixels.
drawPoints:Array
Read only Array holding all calculated points from last draw attempt.
radius:Number
A shorthand property setting all Polygon points radius to
same value. When accessed in GET context this property will return null
if all Pentagon points are not equal, otherwise numeric representation
will be returned.
Public methods:
Method
Description
Polygon(host:MovieClip, level:Number)
Constructor function for new Polygon instance.
Argument host defines parent clip that should host Polygon
instance. level is optional argument, if it's not provided host.getNextHighestDepth()
will be used instead. Make sure you provide this argument in case you
have v2 components in application there's been issues with getNextHighestDepth
in case they're used.
addPoint(x:Number, y:Number, r:Number):Void
Method adds point to current points.
Arguments are - x and y coordinates according to MovieClip registration
point or drawX and dawY, r stands for radius of that point.
modifyPoint(index:Number, propertys:Object):Void
Modify point by zero based index. propertys is supposed to
object optionally containing x ,y and/or r propertys which will be applied
to specified point.
clearPoints(Void):Void
Remove all points.
reset(Void):Void
Reset instance propertys back to initial state.
drawOutline(__props:Object):Void
This function will draw outline of object with no fill. If no lineSize
value is set thickness of 1 pixel will be used.
The only optional argument __props is supposed to be an object containing
all necessary values in form {instanceProperty:value}
drawSolid(__props:Object):Void
This function will draw object with solid fill. If no lineRgb value
is set 0x0 will be used instead.
Propertys used for this method are fillRgb, fillAlpha and line style
values.
The only optional argument __props is supposed to be an object containing
all necessary values in form {instanceProperty:value}
drawGradient(__props:Object):Void
This function will draw object with gradient fill.
This method will halt if no gradientColors is set, all other gradient
fill propertys can be generated.
See com.jR.Drawing.Base for gradient fill propertys.
The only optional argument __props is supposed to be an object containing
all necessary values in form {instanceProperty:value}
class com.jR.Drawing.Rectangle extends com.jR.Drawing.Polygon
This class extends com.jR.Drawing.Polygon in order to provide interface for
creating Rectangles.
When setting point radius points are counter starting from 1, assuming that
top left corner is number 1 continuing clockwise.
*Since this class is extending com.jR.Drawing.Base it is inheriting all
propertys and methods of that class.
Usage: The most basic square outline
import com.jR.Drawing.Rectangle;
var myRectangle:Rectangle = new Rectangle(_root, 1);
myRectangle.width = 100;
myRectangle.height = 100;
myRectangle.drawOutline({drawX:10, drawY:10});
The script above will produce this:
Round corners and solid fill
import com.jR.Drawing.Rectangle;
var myRectangle:Rectangle = new Rectangle(_root, 1);
myRectangle.width = 100;
myRectangle.height = 100;
myRectangle.radius = 30;
myRectangle.lineStyle(2, 0xFF0000);
myRectangle.fillRgb = 0x123456;
myRectangle.fillAlpha = 50
myRectangle.drawSolid({drawX:10, drawY:10});
The script above will produce this:
Some round corners and gradient fill
import com.jR.Drawing.Rectangle;
var myRectangle:Rectangle = new Rectangle(_root, 1);
A shorthand property setting all Polygon points radius to
same value. When accessed in GET context this property will return null
if all Pentagon points are not equal, otherwise numeric representation
will be returned.
radius1:Number
Point 1 radius
radius2:Number
Point 2 radius
radius3:Number
Point 3 radius
radius4:Number
Point 4 radius
Public methods:
This class doesn't have public methods of it's own. All necessary methods
are inherited from com.jR.Drawing.Polygon.
class com.jR.Drawing.Triangle extends com.jR.Drawing.Polygon
This class extends com.jR.Drawing.Polygon in order to provide interface for
creating Triangles.
When setting point radius points are counter starting from 1, assuming that
bottom left corner is number 1 continuing clockwise.
*Since this class is extending com.jR.Drawing.Base it is inheriting all
propertys and methods of that class.
A shorthand property for setting all radiuses in one statement.
x1:Number
Read/write reference to x coordinate of point1
x2:Number
Read/write reference to x coordinate of point2
x3:Number
Read/write reference to x coordinate of point3
y1:Number
Read/write reference to y coordinate of point1
y2:Number
Read/write reference to y coordinate of point2
y3:Number
Read/write reference to y coordinate of point3
r1:Number
Radius of point1
r2:Number
Radius of point2
r3:Number
Radius of point3
Public methods:
Method
Description
Triangle(host:MovieClip, level:Number)
Constructor function for new Triangle instance.
Argument host defines parent clip that should host Triangle
instance. level is optional argument, if it's not provided host.getNextHighestDepth()
will be used instead. Make sure you provide this argument in case you
have v2 components in application there's been issues with getNextHighestDepth
in case they're used.