This blog isn't maintained anymore. Check out my current project, an agile/scrum management tool.

Thursday, June 07, 2007

AS3 Drawing API oddity

I have a weird bug that I'm having trouble figuring out. I have the following code:

comp.graphics.clear();
comp.graphics.lineStyle(5, 0x888888);
comp.graphics.moveTo(0,0);
comp.graphics.lineTo(0,50);
comp.graphics.lineStyle(0, 0);
comp.graphics.beginFill(0x188888);
comp.graphics.drawCircle(10,10,5);
comp.graphics.endFill();

I would expect that to draw a vertical grey line with a filled in circle to the right of it. What I actually get is this:



It's like flash is drawing my circle and then doing a flood-fill outside the circle instead of inside it like it should. If I remove the call to drawCircle(), I get similar results but without the circle.

My solution was to draw the line and the circle on different objects, but I'm unclear on why this is necessary.

Labels:

3 Comments:

  • I believe it's because you have to finish each draw you do with endFill() other wise, it thinks it's an unfinished "box"

    So, you'd have to split those up into drawing your gray line, endFill(), then draw the circle.

    The code below gives me a gray line, then the circle like you describe:

    comp.graphics.clear();
    comp.graphics.beginFill(0x188888, 0);
    comp.graphics.lineStyle(5, 0x888888);
    comp.graphics.moveTo(0,0);
    comp.graphics.lineTo(0,50);
    comp.graphics.endFill();


    comp.graphics.beginFill(0x188888);
    comp.graphics.lineStyle(0, 0);
    comp.graphics.drawCircle(10,10,5);
    comp.graphics.endFill();

    By Anonymous Anonymous, At 6/07/2007 6:41 AM  

  • Sure enough, that works.

    So if I use a fill anywhere, I should use a fill on every single discrete drawing operation?

    Seems like a bug to me, but if that's the case it's easy enough to work around.

    By Blogger Marc, At 6/07/2007 7:01 AM  

  • Looks like a bug to me as well.

    It's not limited to drawing circles, as rects cause the same issue.

    A simple workaround is to slip a moveTo in there to disconnect the original line from the circle draw:

    comp.graphics.clear();
    comp.graphics.lineStyle(5, 0x888888);
    comp.graphics.moveTo(0,0);
    comp.graphics.lineTo(0,50);

    --comp.graphics.moveTo(0,0);--

    comp.graphics.lineStyle(0, 0);
    comp.graphics.beginFill(0x188888);
    comp.graphics.drawCircle(10,10,5);
    comp.graphics.endFill();

    By Anonymous Anonymous, At 6/07/2007 8:23 AM  

Post a Comment

Subscribe to Post Comments [Atom]



<< Home