AS3 'drawPath' simple triangle not drawing correctly - why?

I want to draw a simple triangle in ActionScript 3.

I use the ‘drawPath’ method of ‘Graphics’ class.

here is the code snippet:


stage.stage.quality = StageQuality.LOW;         // Change quality to low so no anti-aliasing occurs
var trianglePoints:Vector.<Number> = new Vector.<Number>();


trianglePoints.push(0);     trianglePoints.push(0);     // Coordinate (0,0)
trianglePoints.push(20);    trianglePoints.push(0);     // Coordinate (20,0)
trianglePoints.push(20);    trianglePoints.push(20);    // Coordinate (20,20)
trianglePoints.push(0);     trianglePoints.push(0);     // Coordinate (0,0) - tried with and without this coordinate return


var commands:Vector.<int> = new Vector.<int>(4);
commands.push(1);   // Move to
commands.push(2);   // Line to
commands.push(2);   // Line to
commands.push(2);   // Line to


var drawSprite:Sprite = new Sprite();


drawSprite.graphics.beginFill(0xFFFF0000);          // Color Red
drawSprite.graphics.drawPath(commands, trianglePoints); // Draw the path
drawSprite.graphics.endFill();


var bd:BitmapData = new BitmapData(100, 100, true, 0x0000FF00);
bd.draw(drawSprite);


var pngBytes:ByteArray = PNGEnc.encode(bd);
var fileReference:FileReference = new FileReference();
fileReference.save(pngBytes,"bd_custom_draw.png");


stage.stage.quality = StageQuality.HIGH;

I don’t know why - but instead of the triangle having points at :
[LIST]
*
*
*
[/LIST]

The triangle drawn has points at :
[LIST]
*
*
*
[/LIST]

Here is a screenshot I took from Paint-Brush, with the pixels shown:

Why is the triangle not drawn in the right coordinates ??

Upadte :

I have tried to add this line just before the ‘drawPath’:

currentMask.graphics.lineStyle(1, 0xFFFF0000);

and this is the result I get:

I just can’t seem to get the result I need !
Why can’t I get Action-Script to draw the triangle correctly ??