PDA

View Full Version : I'm looking for a line following a drag and drop object


held
01-13-2005, 01:03 PM
Hi,

I'm fairly new to programming, and it's the first time i visit a forum like this one. I looked at several forums, but can't seem to find what I'm looking for.....

What I need is a line that is locked to one point and attached to an object on the other point. When dragging that object, the line should folow the object in the most dynamic way possible....
I know the drag and drop script, it's the following line that bothers me, if anyone has a clue? Thanks a million,

held.

Xeef
01-13-2005, 01:42 PM
hi and welcome to As.Org

function LineFolow(Target, x, y) {
_root.createEmptyMovieClip("Line", 1);
with (_root.Line) {
lineStyle(1, 0xFF00FF, 100);
moveTo(x, y);
lineTo(Target._x, Target._y);
}
}
setInterval(LineFolow, 10, My_mc, 0, 0);

held
01-13-2005, 03:55 PM
Thanks allot, I'll try it out later, gotta go to class first...
I'll let you know if it works..

Held.

held
01-14-2005, 12:55 AM
I tried it out, and it did create line when i draged my object, but not like I was looking for. I want one line to folow my object, like if you take a showerhead, theres always a tube folowing it where the water runs through, know what I mean.
What I actualy want to do is make a stetoscope...

Thanks for your quick reply though,

greetings,

held.

Bosworth
01-14-2005, 03:56 AM
nifty code, X

- just spent an hour playing with it (added multiple movie clips, each controlling a point on the created line.. - then added random movement to the objects - i can easily see how, if pushed a bit - begins to create all those sweet random line animations that hooked me on flash in the first place...)

:)

Xeef
01-14-2005, 02:42 PM
Hmmm

still not know what you want

but try this (not perfect but not to bad)

on (press) {
this.startDrag();
this.x = 550;
this.y = 500;
this.MaxLength = 50;
this.onEnterFrame = function() {
q = _root.getNextHighestDepth();
var Caller = this;
var O = _root.createEmptyMovieClip(q, q);
with (O) {
lineStyle(1, 0x00000, 100);
X = Caller._x+(-5+random(11));
Y = Caller._y+(-5+random(11));
xx = Caller.x+(-5+random(11));
yy = Caller.y+(-5+random(11));
xxx = X-xx;
yyy = Y-yy;
z = xxx/yyy;
moveTo(0, 0);
L = Caller.MaxLength*Math.random();
lineTo(L*z, L*z/Math.abs(z));
}
O._x = X;
O._y = Y;
O.X = xx;
O.Y = yy;
O.onEnterFrame = function() {
if (Math.abs((this.X-this._x)/10)<.1 && Math.abs((this.Y-this._y)/10)<.1) {
delete this.onEnterFrame;
this.removeMovieClip();
}
this._x += (this.X-this._x)/10;
this._y += (this.Y-this._y)/10;
};
};
}
on (release) {
delete this.onEnterFrame;
this.stopDrag();
}