Skip to main content
Participant
September 29, 2010
Question

how to draw a line in flex 4

  • September 29, 2010
  • 1 reply
  • 10466 views

hello,

I can't figure out how to draw programatically a simple line from one point to another. It should be easy but couldn't do it...

thanks for any help.

    This topic has been closed for replies.

    1 reply

    September 29, 2010

    You can draw lines in MXML or in ActionScript:

        <s:Line xFrom="20" yFrom="20" xTo="100" yTo="100">
            <s:stroke>
                <s:SolidColorStroke color="black"/>
            </s:stroke>
        </s:Line>
        <s:Line xFrom="100" yFrom="20" xTo="20" yTo="100">
            <s:stroke>
                <s:SolidColorStroke color="gray" alpha=".6" weight="10"/>
            </s:stroke>
        </s:Line>

    var canvas:Sprite = new Sprite();
    addChild(canvas);
    stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    stage.addEventListener(MouseEvent.MOUSE_UP, stop_drawing);
    function mouseDownHandler(event:MouseEvent):void {
        stage.addEventListener(MouseEvent.MOUSE_MOVE, draw_line);   
    }
    function stop_drawing(e:MouseEvent):void
    {
        stage.removeEventListener(MouseEvent.MOUSE_MOVE, draw_line);   
    }

    function draw_line(e:MouseEvent):void
    {   canvas.graphics.lineStyle(1, 0xFF6633);
        canvas.graphics.lineTo(mouseX, mouseY);
        e.updateAfterEvent();
    }

    http://www.actionscript.org/forums/showthread.php3?t=187890

    http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f70.html

    http://www.artima.com/articles/drawing_lines_in_flex_4.html

    If this post answers your question or helps, please mark it as such.


    Greg Lafrance - Flex 2 and 3 ACE certified

    www.ChikaraDev.com

    Flex Training and Support Services

    Participant
    September 29, 2010

    thank u for your answer, but i'm with Flex 4 and was looking for something that use the Line class with beginDraw() and draw() methods. Because I have to draw it programatically.

    Participant
    October 5, 2010

    hello,

    it's me again

    anyone knows how to draw a line in flex 4 with actionscript ?