views:

33

answers:

2

i'm attempting to draw lines beside each other, but the last line from the first color group takes on the color from the second color group before the second color is assigned. can anyone explain this?

function drawCorner()
    {
    var corner:Sprite = new Sprite();
    corner.graphics.beginFill(0x0, 1.0);
    corner.graphics.drawRect(0, 0, 20, 20);

    corner.graphics.lineStyle(0, 0x00FF00, 1.0);    
    corner.graphics.moveTo(1, 13);
    corner.graphics.lineTo(13, 1);
    corner.graphics.moveTo(6, 13);
    corner.graphics.lineTo(13, 6);
    corner.graphics.moveTo(11, 13);
    corner.graphics.lineTo(13, 11);

    corner.graphics.lineStyle(0, 0xFF00FF, 1.0);    
    corner.graphics.moveTo(0, 13);
    corner.graphics.lineTo(13, 0);
    corner.graphics.moveTo(5, 13);
    corner.graphics.lineTo(13, 5);
    corner.graphics.moveTo(10, 13);
    corner.graphics.lineTo(13, 10);

    corner.graphics.endFill();

    addChild(corner);
    }
+2  A: 

While I am not entirely sure why this is happening, it is happening because of your placement of corner.graphics.endFill();

Place the endFill call immediately after the drawRect and the problem is resolved.

sberry2A
ahh! indeed it is. thanks for figuring that out.
TheDarkInI1978
+1  A: 

You can also put the

corner.graphics.moveTo(0, 13);

before you change lineStyle.

Zev
you're right. the whole thing seems a bit counter-intuitive, though. even having to end the fill prior to making the line color changes is a bit ridiculous. i suppose i can see there's no real benefit to ending the fill last in the function, and doing so can make the code more difficult to read, but i still feel like filing a bug to adobe about this.
TheDarkInI1978