Rectangle Documentation
Author: Alex Uhlmann
Last Modified: 09/23/05 19:46:21
Summary
Rectangle class:
Rectangle Properties:
Rectangle Methods:
version: Documentation not provided.
description:
Rectangle is a class for creating rectangles. If you specify a movieclip as first parameter, the shape will be drawn inside this movieclip. If you omit the mc parameter, the class will create a new movieclip in _root.apContainer_mc.
Example 1: draw a rectangle with default parameters.
Example 2: draw a rectangle with custom parameters.var myRectangle:Rectangle = new Rectangle(); myRectangle.draw();
Example 3: If we scale our rectangle from example 2 with the MovieClip._xscale, MovieClip._yscale properties, the outline will scale too. If you want the outline to stay fixed and just scale the fill, you need to redraw the rectangle in each step. This allows the setSize method. Let's do a test to illustrate this: After the code from example 2, write:var myRectangle:Rectangle = new Rectangle(275,200,100,100); myRectangle.lineStyle(2,0x000000,100); myRectangle.fillStyle(0xff0000,100); myRectangle.draw();
(Example .swf) You'll notice the that the outline also scaled. Instead using the Scale class, use setScale() in combination with the Animator class from the ultility package.new Scale(myRectangle.movieclip).run(400,400);
var myAnimator:Animator = new Animator();
myAnimator.caller = myAnimator;
myAnimator.start = [myRectangle.getSize().w,myRectangle.getSize().h];
myAnimator.end = [400,400];
myAnimator.setter = [[_root,"scale"]];
myAnimator.run();
//Proxy class.
function scale(w:Number,h:Number) {
myRectangle.setSize(w,h);
myRectangle.draw();
}
(Example .swf)
See Animator class.
usage:
var myRectangle:Rectangle = new Rectangle();
var myRectangle:Rectangle = new Rectangle(x, y, width, height);
var myRectangle:Rectangle = new Rectangle(mc, x, y, width, height);
parameters:
(Number)(static) default property. width of rectangle. Defaults to 100.
(Number)(static) default property. height of rectangle. Defaults to 100.
(MovieClip)(read only) Movieclip that contains the drawing.
(Number) Outline thickness.
(Number) Outline color of the drawing as hex number.
(Number) Outline transparency (alpha).
(Number) Fill color of the drawing.
(Number) Fill transparency.
description: Draws the rectangle.
usage:
myRectangle.draw();
returns: Void.
description: Draws the shape without clearing the movieclip.
usage:
myInstance.drawBy();
returns: Void.
description: Returns the dimensions of the rectangle.
usage:
myRectangle.getSize();
returns: Object that contains w for with and h for height properties that define the dimension of the drawing in pixels.
description: Sets the dimensions of the rectangle.
usage:
myRectangle.setSize(width, height);
parameters:
returns: Void.
description: define outline.
usage:
myRectangle.lineStyle();
myRectangle.lineStyle(lineThickness, lineRGB, lineAlpha);
parameters:
returns: Void.
description: define fill.
usage:
myRectangle.fillStyle();
myRectangle.fillStyle(fillRGB, fillAlpha);
parameters:
returns: Void.
description: Same interface as MovieClip.beginGradientFill(). See manual.
usage:
myShapeComposite.gradientStyle(fillType, colors, alphas, ratios, matrix);
parameters:
returns: Void.
description: Sets the registration point of the shape. Defaults to center. Top left is 0,0. The parameter object accepts either a position property with the value of "CENTER" or x and y properties of with coordinates as values of the registration point.
Example 1: Set the registration point of an ellipse to the upper left corner (0,0) instead of center.
var myEllipse:Ellipse = new Ellipse(275,200,100,50);
myEllipse.setRegistrationPoint( {x:0,y:0} );
myEllipse.draw();
internally AnimationPackage centers all shapes with
myInstance.setRegistrationPoint( {position:"CENTER"} );
usage:
myInstance.setRegistrationPoint(registrationObj);
parameters:
returns: Void.
description: removes all drawings. Identical to myInstance.movieclip.clear();
usage:
myInstance.clear();
returns: Void.
description: returns a unique ID of the instance. Usefull for associative arrays.
usage: myInstance.getID();
returns: Number
description: returns the name of the class.
usage: myInstance.toString();
returns: String