all groups > flash actionscript > september 2005 >
You're in the

flash actionscript

group:

Need Help coding a drag issue


Need Help coding a drag issue sandyrivers
9/23/2005 7:37:13 PM
flash actionscript:
Hello all,

I'm working on a project that has me stumped. Can someone help me or get me
started with this code?

Here is what I need to do: I need to show a thick (at least 3 pt) line that
connects a draggable object to a fixed object so that the line connects the two
obects wherever the user drags the moveable one.

Sort of like if one person stands hlding a rope and another person grabs the
other end and walks around with it, the rope "grows" with the moving person.

I have to be able to duplicate this code 32 times as well, becuase in my
project there are 32 items that need to be manipulated, each with their own
fixed point.

I'm very grateful for any assistance. I'm completely stumped on this one (I
use flash mainly for animation, and light coding purposes).

I'm running MX04.

Thanks!

-Sandy
Re: Need Help coding a drag issue mandingo
9/23/2005 11:54:39 PM
this.drawLine = function(to){
this.moveTo(this._x,this._y);
this.lineStyle(1,0x999999,100);
this.lineTo(to._x,to._y);
}
this.onEnterFrame = function(){
this.drawLine(this._parent.targetMovieClipName);
}

I haven't tested that... but that should get you started... in the function in
the onEnterFrame just rename the targetMovieClipName with your movieClip name
and see what that does...

that may need a tweak or two... (actually will but will get you started)

cheers
Re: Need Help coding a drag issue NSurveyor
9/24/2005 12:00:00 AM
Your code is flawed, a bit. Because, since you are drawing INSIDE the
movieclip, you should be moving to 0,0 not this._x,this._y. And the to._x and
to._y would need to be changed as well. You could do:

//On first frame
MovieClip.prototype.drawLineTo = function(clip) {
this.moveTo(0, 0);
var p = {x:0, y:0};
clip.localToGlobal(p);
this.globalToLocal(p);
this.lineTo(p.x, p.y);
};
function drawLineBetween(mc1, mc2) {
mc1.onMouseMove = function() {
with (this) {
clear();
lineStyle(3, 0xFF0000, 100);
drawLineTo(mc2);
}
updateAfterEvent();
};
}
//Later on:
drawLineBetween(my_mc1, my_mc2);
Re: Need Help coding a drag issue sandyrivers
9/24/2005 5:58:45 PM
Thanks everyone! I was able to get the problem solved late last night.

I appreciate your help!

Re: Need Help coding a drag issue NSurveyor
9/24/2005 6:00:37 PM
AddThis Social Bookmark Button