-
Senior Member
generating lines between dragable mc's
hi there,
i have 4 draggable mc's,
i can generate lines joining them, but when i drag the mc's the line moves to the correct coordinates but it duplicates its self.
please look at my script and tr to correct it
code: _root.createEmptyMovieClip("myLine", 1);
_root.createEmptyMovieClip("myLine1", 2);
_root.createEmptyMovieClip("myLine2", 3);
_root.createEmptyMovieClip("myLine3", 4);
myLine.moveTo(_root.mc._x, _root.mc._y);
myLine1.moveTo(_root.mc1._x, _root.mc1._y);
myLine2.moveTo(_root.mc2._x, _root.mc2._y);
myLine3.moveTo(_root.mc3._x, _root.mc3._y);
myLine.onEnterFrame = function() {
myLine.lineTo(_root.mc._x, _root.mc._y);
myLine.lineStyle(.05, 0x00ff00, 101);
myLine.lineTo(_root.mc1._x, _root.mc1._y);
myLine.updateAfterEvent();
};
myLine1.onEnterFrame = function() {
myLine1.lineTo(_root.mc1._x, _root.mc1._y);
myLine1.lineStyle(.05, 0x00ff00, 101);
myLine1.lineTo(_root.mc2._x, _root.mc2._y);
myLine1.updateAfterEvent();
};
myLine2.onEnterFrame = function() {
myLine2.lineTo(_root.mc2._x, _root.mc2._y);
myLine2.lineStyle(.05, 0x00ff00, 101);
myLine2.lineTo(_root.mc3._x, _root.mc3._y);
myLine2.updateAfterEvent();
};
myLine3.onEnterFrame = function() {
myLine3.lineTo(_root.mc3._x, _root.mc3._y);
myLine3.lineStyle(.05, 0x00ff00, 101);
myLine3.lineTo(_root.mc._x, _root.mc._y);
myLine3.updateAfterEvent();
};
many thanks.
zlatan...
-
You need to tell the movieclips to clear what has already been drawn:
_root.createEmptyMovieClip("myLine", 1);
_root.createEmptyMovieClip("myLine1", 2);
_root.createEmptyMovieClip("myLine2", 3);
_root.createEmptyMovieClip("myLine3", 4);
myLine.moveTo(_root.mc._x, _root.mc._y);
myLine1.moveTo(_root.mc1._x, _root.mc1._y);
myLine2.moveTo(_root.mc2._x, _root.mc2._y);
myLine3.moveTo(_root.mc3._x, _root.mc3._y);
myLine.onEnterFrame = function() {
clear();
myLine.lineTo(_root.mc._x, _root.mc._y);
myLine.lineStyle(.05, 0x00ff00, 101);
myLine.lineTo(_root.mc1._x, _root.mc1._y);
myLine.updateAfterEvent();
};
myLine1.onEnterFrame = function() {
clear();
myLine1.lineTo(_root.mc1._x, _root.mc1._y);
myLine1.lineStyle(.05, 0x00ff00, 101);
myLine1.lineTo(_root.mc2._x, _root.mc2._y);
myLine1.updateAfterEvent();
};
myLine2.onEnterFrame = function() {
clear();
myLine2.lineTo(_root.mc2._x, _root.mc2._y);
myLine2.lineStyle(.05, 0x00ff00, 101);
myLine2.lineTo(_root.mc3._x, _root.mc3._y);
myLine2.updateAfterEvent();
};
myLine3.onEnterFrame = function() {
clear();
myLine3.lineTo(_root.mc3._x, _root.mc3._y);
myLine3.lineStyle(.05, 0x00ff00, 101);
myLine3.lineTo(_root.mc._x, _root.mc._y);
myLine3.updateAfterEvent();
};
................
www.oc88.com
................
-
Senior Member
mate, thanks for the help but it didnt work,
n e other ideas?
thanks,
zlatan..
-
Banned
Hi,
This will work for 2 movieclips. I have not tried to extend it to more than 2 ....
code:
function makeLine(name, depth, lineSize, color, alpha, posA, posB) {
this.createEmptyMovieClip(name, depth);
with (this[name]) {
lineStyle(lineSize, color, alpha);
moveTo(_root[posA]._x, _root[posA]._y);
lineTo(_root[posB]._x, _root[posB]._y);
}
}
_root.onEnterFrame = function() {
makeLine("line", 1, 2, "0xFF0000", 100, "mc1", "mc2");
}
_root.MC2.onPress = function() {
startDrag("MC2");
}
_root.MC2.onRelease = function() {
stopDrag();
}
_root.MC1.onPress = function() {
startDrag("MC1");
}
_root.MC1.onRelease = function() {
stopDrag();
}
-
Senior Member
no luck, that didnt work either!?
-
Let's say we have 4 movieClips "mc1","mc2","mc3" and "mc4". Then just put this code on the first frame.
Code:
MovieClip.prototype.dragMe = function(){
this.onPress = function(){
this.startDrag(false)
}
this.onRelease = this.onReleaseOutside = function(){
this.stopDrag()
}
}
for(i=1;i<=4;i++){
_root["mc"+i].dragMe();
_root.createEmptyMovieClip("myLine"+i, i);
this["myLine"+i].moveTo(_root["mc"+i]._x,_root["mc"+i]._y)
}
this.onMouseMove = function(){
with(myLine1){
clear();
lineTo(_root.mc1._x, _root.mc1._y);
lineStyle(.05, 0x00ff00, 100);
lineTo(_root.mc2._x, _root.mc2._y);
};
with(myLine2){
clear()
lineTo(_root.mc2._x, _root.mc2._y);
lineStyle(.05, 0x00ff00, 100);
lineTo(_root.mc3._x, _root.mc3._y);
};
with(myLine3){
clear();
lineTo(_root.mc3._x, _root.mc3._y);
lineStyle(.05, 0x00ff00, 100);
lineTo(_root.mc4._x, _root.mc4._y);
};
with(myLine4){
clear();
lineTo(_root.mc4._x, _root.mc4._y);
lineStyle(.05, 0x00ff00, 100);
lineTo(_root.mc1._x, _root.mc1._y);
};
updateAfterEvent();
}
You can see that some parts of the code are almost the same. So we can write this code in more simple way.
-
Senior Member
ledgend!!!
if you may, one more question, how do i set up hittests for the lines?
i have tried
code: onClipEvent (enterFrame) {
setProperty(_root.bal, _x, getProperty(this, _x)+_root.val);
setProperty(_root.bal, _y, getProperty(this, _y)+_root.valy);
if ((this.hitTest(_root.myLine1._x, _root.myLine1._y, true))||(this.hitTest(_root.myLine2._x, _root.myLine2._y, true))||(this.hitTest(_root.myLine3._x, _root.myLine3._y, true))||(this.hitTest(_root.myLine4._x, _root.myLine4._y, true))){
_root.val *= -1;
_root.valy *= -1;
}
trace((this.hitTest(_root.myLine1._x, _root.myLine1._y, true))||(this.hitTest(_root.myLine2._x, _root.myLine2._y, true))||(this.hitTest(_root.myLine3._x, _root.myLine3._y, true))||(this.hitTest(_root.myLine4._x, _root.myLine4._y, true)))
}
Last edited by dudeqwerty; 05-31-2005 at 04:22 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|