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

**URL:** <https://forum.kirupa.com/t/as3-drawpath-simple-triangle-not-drawing-correctly-why/329932>\
**Category:** flash\
**Created:** [November 9, 2012, 3:16pm UTC](https://forum.kirupa.com/t/as3-drawpath-simple-triangle-not-drawing-correctly-why/329932 "2012-11-09T15:16:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flivor2012](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@Flivor2012](https://forum.kirupa.com/u/Flivor2012)\
**Post date:** [November 9, 2012, 3:16pm UTC](https://forum.kirupa.com/t/as3-drawpath-simple-triangle-not-drawing-correctly-why/329932/1 "2012-11-09T15:16:19Z")

</div>

I want to draw a simple triangle in ActionScript 3.

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

here is the code snippet:

```auto

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:

![](http://s8.postimage.org/7npsvhvpv/alpha_Bitmap_Data_custom_draw.png)

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

**Upadte :**

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

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

```

and this is the result I get:

![](http://s8.postimage.org/x6hn1g183/alpha_Bitmap_Data_custom_draw_with_line.png)

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