A: 

You'd want to override the UIComponent method updateDisplayList() on the Canvas and do your drawing in there.

This is assuming you are familiar with line drawing in AS3 in general.

Ben Throop
This isn't quite what I meant. I've managed to get the line to redraw in the new location, but this only happens after I stop dragging the mx:Panels. I would like the redrawing to take place also while things are moving around.
bgoncalves
+2  A: 

"I've tried overriding the updateDisplayList() method of the mx:Canvas component but that seems to only update the drawing after the dragging. I would like for the line to follow the mx:Panel as it is being dragged."

You can listen to MoveEvent.MOVE events in the Panels and have the handler call for the redrawing of the lines, and then have the Panels dispatch these events while they are being dragged by listening for MouseEvent.MOUSE_MOVE events in the stage and dispatching the MOVE event in the handler (attach this handler to the stage in the Panel's MouseEvent.MOUSE_DOWN event handler, along with a handler for MouseEvent.MOUSE_UP (attached to the stage as well) -- then remove both of these event listeners from the stage in the MOUSE_UP handler.)

Here's an example (this would be in the Panel subclass:)

private function attachListeners():void
{
    this.addEventListener(MouseEvent.MOUSE_DOWN, selfMouseDownHandler, false,0,true);
    this.addEventListener(MoveEvent.MOVE, selfMoveHandler, false,0,true);
}

private function selfMoveHandler(event:MoveEvent):void
{
    redrawConnectedLinks();
}

private function selfMouseDownHandler(event:MouseEvent):void
{
    stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUpHandler, false,0,true);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, stageMouseMoveHandler, false,0,true);
}

private function stageMouseUpHandler(event:MouseEvent):void
{
    stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUpHandler, false);
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, stageMouseMoveHandler, false);
}

private function stageMouseMoveHandler(event:MouseEvent):void
{
    dispatchEvent(new MoveEvent(MoveEvent.MOVE));
}
hasseg
Humm... This seems to work similarly to the previous solution. It only updates when I "drop" the panel and not while it's moving.
bgoncalves
(You can test it by adding a trace to the coordsChangedHandler() function )
bgoncalves
Ok, thanks for the info -- I changed the suggestion to something that has actually worked for me.
hasseg
Still not there (see EDIT3 above). Maybe I'm missing something?
bgoncalves
Added a code example to illustrate my confusing explanation. Hope that helps :)
hasseg
Works great! Thanks for all the help!
bgoncalves
+1  A: 

flexwires is an open source project to implement this type of "connected lines" UI paradigm in Flex. It might just fit your needs.

joshtynjala
Flex wires looks interesting. Thanks for the reference.
Gordon Potter
A: 

Can't you use bind functionality here? the end point of the line bound to the center of the circle?

A: 

New to flash/flex and had a similar problem. I solved it by attaching an event listener to the Enter_Frame event. I am not sure if this is the most efficient solution since it redraws even if the objects have not moved but it worked for me:

    import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;

public class Association extends Sprite
{
    private var t1:DisplayObject;
    private var t2:DisplayObject;
    //Connects two objects
    public function Association(t1:DisplayObject, t2:DisplayObject)
    {
        this.t1=t1;
        this.t2=t2;
        this.addEventListener(Event.ENTER_FRAME, redraw)
        super();
    }

    public function redraw(event:Event):void
    {
        graphics.clear();
        graphics.lineStyle(2,0x000000);
        graphics.moveTo(t1.x,t1.y);
        graphics.lineTo(t2.x,t2.y);
    }

}
Ben
A: 

Hi Ben, I want to draw the line between these two components in exactly similar way... But additionally there is a constraint that i have. I will first click on a button that says "Connect Components". Then i will have to click on the components one by one, and the rest is the same as discussed above. Could you please elaborate on the whole process? I am quite new to this event handling stuff...

Ronnie