PDA

View Full Version : flash/actionscript help



easymazuma
June 11th, 2008, 05:27 PM
I have a line connecting two objects. But one of the objects is draggable. How can I keep it so that the line stays connected to the draggable object, and expands or gets shorter as the dragged object is dragged around the screen? Here is a picture:

http://img381.imageshack.us/img381/7158/ideaxs5.gif

The picture is draggable and I need the line to stay connected at all times and adject. Thanks for the help.

snickelfritz
June 11th, 2008, 08:33 PM
This sort of works.
Sorry, I don't have time to fiddle with it any longer.
GL
Example:http://www.byrographics.com/AS3/dragBox/dragBox.html (http://www.byrographics.com/AS3/dragBox/dragBox.html)

/*
There's a movieclip on the stage instance name: "box"
This is the little picture you drag around the stage.
*/
box.addEventListener(MouseEvent.MOUSE_DOWN, boxDown, false, 0, true);
stage.addEventListener(MouseEvent.MOUSE_UP, boxUp, false, 0, true);

function boxDown(e:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_MOVE, boxMove);
Yoffset = mouseY - box.y;
Xoffset = mouseX -box.x;
}

function boxUp(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, boxMove);
}

var Yoffset:Number;
var Xoffset:Number;
var canvas:Shape = new Shape();
addChild(canvas);
var g:Graphics = canvas.graphics;

function boxMove(e:MouseEvent):void {

box.y = mouseY - Yoffset;
box.x = mouseX - Xoffset;
Yoffset = mouseY - box.y;
Xoffset = mouseX - box.x;

g.clear();
g.lineStyle(1, 0x000000);
g.moveTo(200, 200);
g.lineTo(mouseX, mouseY);

addChild(box);
e.updateAfterEvent();
}