Thursday, May 03, 2007

Undocumented ActionScript 3

One of the things that I hung my hat on for a while in ActionScript 2 was this class for drawing boxes with corners of any radius. In ActionScript 3, they happen to have such a function built in but they don't like to talk about it. Apparently, it is used by some component in Flex but is not in any of their documentation. Doing searches might bring up some old beta syntax but this is the final:

displayObject.graphics.drawRoundRectComplex( x, y, width, height, tl-corner, tr-corner, br-corner, bl-corner );

Works great, and all in one line! I can't even begin to tell you how complicated my AS2 one was. Here is a full example:
var element:Sprite = new Sprite();
element.graphics.beginFill( 0xFF3300, 100 );
element.graphics.drawRoundRectComplex( 10, 10, 100, 100, 5, 10, 5, 0 );
element.graphics.endFill();
addChild(element);

Labels:

3 Comments:

Blogger Pherank said...

This is great to know about, actually. Thanks.

6:36 PM  
Blogger Pherank said...

This is great to know about, actually. Thanks.

6:36 PM  
Blogger Unknown said...

The component you are speaking of is DateChooser. It uses the following code to update its display list.

var calHG:Graphics = calHeader.graphics;
calHG.clear();
var matrix:Matrix = new Matrix();
matrix.createGradientBox(w, headerHeight, Math.PI / 2, 0, 0);
calHG.beginGradientFill(GradientType.LINEAR,
headerColors,
//[0xFF0000,0x00FF00],
[1.0,1.0],
[ 0, 0xFF ],
matrix);
GraphicsUtil.drawRoundRectComplex(calHG, borderThickness, borderThickness,
w, headerHeight, cornerRadius, cornerRadius, 0, 0);
calHG.endFill();
calHG.lineStyle(borderThickness, borderColor);
calHG.moveTo(borderThickness, headerHeight + borderThickness);
calHG.lineTo(w + borderThickness, headerHeight + borderThickness);

8:12 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home