Hi,
I am creating a drag and drop where the user drags an object to the target and in doing so they create a line between where the object started and the target.
I have got this working fine for one set of objects, however, if there are three on the screen the drawline function only works for the first one, the others do not draw a line.
Is there a method I should be using so that I can have multiple objects and targets with lines drawn between them?
Code is here :
PHP Code:
// code for UK
_root.createEmptyMovieClip("line_mc", 1);
onMouseMove = function(){
updateAfterEvent();
}
MovieClip.prototype.drawLine = function()
{
this.clear();
this.lineStyle(2,0xFF9900,100);
this.moveTo(mc1._x, mc1._y);
this.lineTo(mc2._x, mc2._y);
this.x = this._x;
this.y = this._y;
}
// ensure movieclips are in front of line
mc1.swapDepths(2);
mc2.swapDepths(3);
// draw initial line
line_mc.drawLine();
mc2.onPress = function()
{
this.startDrag();
line_mc.onEnterFrame = drawLine;
}
mc2.onRelease = function()
{
delete line_mc.onEnterFrame;
this.stopDrag();
checkTarget(this);
if (eval(this._droptarget) == uktarget) {
this._x = uktarget._x;
this._y = uktarget._y;
} else if (eval(this._droptarget) == francetarget) {
this._x = francetarget._x;
this._y = francetarget._y;
}else if (eval(this._droptarget) == germantarget) {
this._x = germantarget._x;
this._y = germantarget._y;
} else {
this._x = this.x;
this._y = this.y;
}
}
function checkTarget(drag){
// trace(drag+ "has been dropped on "+eval(drag._droptarget));
if (drag.hitTest(uktarget)) {
trace(drag+" has been dropped on greyCircle");
} else {
trace("you missed the target");
}
}