Name: connect() - (MX) connects movieclips with sequential lines despite their scope
Author: senocular: www.senocular.com
Date:
1899-12-31T00:26:27.200
Documentation:
MovieClip CONNECT: draws a line in the clip this is used on
connecting to the centerpoints, one after the other of the
movieclips passed.
Arguments:
- points: movieclips (or objects, see below) from which a line will be drawn to. The
order in which they are placed determines the order in which they are connected.
Tip:
- as an alternative to movieclips, you can pass in objects containing _x and _y properties.
Example:
Point = function(x,y){
this._x = x;
this._y = y;
}
a = new Point(0,0);
b = new Point(10,20);
c = new Point(20,0);
Now you can use connect with these points to draw a triangle:
this.lineStyle(0, 0x000000, 100);
this.connect(a,b,c,a);
Connect connects a to b, b to c, then c back to a
Example:
// connects a thin black line betwwen all passed movieclips
// starting with mc1, then to mc2 then to mc3 etc
this.onEnterFrame = function(){
this.clear()
this.lineStyle(0, 0x000000, 100);
this.connect(_parent.mc1, this.mc2, _root.mc3, this.mc2.mc4, _root.mc1.intermediate.mc5);
}
1
2
3
4
5
6
7
8
9
MovieClip.prototype.connect = function(points){
var i, l = arguments.length, coords;
for (i=0; i<l; i++){
arguments[i]._parent.localToGlobal(coords = {x:arguments[i]._x ,y:arguments[i]._y});
this.globalToLocal(coords);
if (!i) this.moveTo(coords.x, coords.y);
else this.lineTo(coords.x, coords.y);
}
}