Hi!
Thanks for the advice!
If you look at the code a bit closer (I know it's a bit complex) You would
see that the moveto is only done on the first point in the loop.
I believe the code does follow you advice as this example will show.
Suppose I have a 4 point array:
point[0] { 1,1}
point[1] { 2,2}
point[2] { 3,1}
point[3] { 1,1}
The the code would run the following commands
moveto (1,1)
beginFill
lineto(2,2)
lineto(3,1)
lineTo(1,1)
endFill
Which should draw a filled triangle, but all I get is the lines, no fill.
-- Carolyn
Re: Filled Polygon
Posted by: "Adam Royle" <mailto:[EMAIL PROTECTED]
Re%3A%20Filled%20Polygon>[EMAIL PROTECTED]
Mon Apr 2, 2007 7:07 am (PST)
Hi Carolyn,
I would say that it's because you are calling
graphics.moveTo
and
graphics.beginFill
during your loop, whereas it should be graphics.lineTo
Change your logic so that you do this (pseudo-code):
clear
lineStyle
moveTo - (starting point)
beginFill
loop {
lineTo - (each point)
}
moveTo - (optional end point)
endFill
Hope this helps.
Cheers,
Adam
----- Original Message -----
From: Carolyn Cole
To: <mailto:flexcoders%40yahoogroups.com>flexcoders@yahoogroups.com
Sent: Monday, April 02, 2007 11:52 PM
Subject: [flexcoders] Filled Polygon
Hello,
For some reason I can not seem to get my polygon created by lineto to fill.
The polygon gets drawn, but the fill never happens. Does anyone have any
suggestions?
The code I am using is bellow:
recColor = 0xFF0000;
transp=0.5;
var graphics:Graphics = recShape.graphics;
graphics.clear();
graphics.lineStyle(3,recColor,100);
graphics.beginFill(recColor,transp);
var lastPoint:Point = null;
for(var i:int=1; i< points.length; i++){
var p1:Point = new Point()
p1.x = points[i-1].x;
p1.y = points[i-1].y;
var p2:Point = new Point();
p2.x = points[i].x;
p2.y = points[i].y;
if (lastPoint == null){
graphics.moveTo(p1.x,p1.y);
graphics.beginFill(recColor,transp);
}
graphics.lineTo(p2.x, p2.y);
lastPoint = p2;
}
graphics.endFill();
Thanks!
-- Carolyn