Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP PLEASE...moving movie clip using averages

Status
Not open for further replies.

ravenchaos

Technical User
Jun 14, 2007
1
US
In flash, I am trying to get a movie clip/object to move to the average between two other objects. In other words, I have dot A (pa) and dot C (pc) and as I move them, I want dot B (pb) to be dead center of the two...can anyone help me figure out how to do this? Here is the script I have so far, and commented out on the bottom is the formula I need, but don't know how to get to work:

pa.onPress = function() {
this.startDrag(false,
_root.groove_1_mc._x,
_root.groove_1_mc._y - 382,
_root.groove_1_mc._x,
_root.groove_1_mc._y);

};
pa.onRelease = function() {
stopDrag();
};

pc.onPress = function() {
this.startDrag(false,
_root.groove_2_mc._x,
_root.groove_2_mc._y - 382,
_root.groove_2_mc._x,
_root.groove_2_mc._y);
};
pc.onRelease = function() {
stopDrag();
};

var pax = pa._x;
var pay = pa._y;
var pcx = pc._x;
var pcy = pc._y;
var cax = pcx - pax;
var cay = pcy - pay;


this.createEmptyMovieClip("cnt", 1000);
cnt.lineStyle(2, 0xFFFFFF, 100);
cnt.moveTo(pa._x, pa._y);
cnt.lineTo(pc._x, pc._y);
cnt.lineTo(pa._x, pa._y);
cnt.moveTo(pa._x, pa._y);

//pb.y (green dot) needs to be equal to the y axis of pa (left red dot) plus the y axis of pc (right red dot) divided by 2
//pb.y = (pa._y + pc._y)/2;
//pb.x (green dot) needs to be equal to the x axis of pa (left red dot) plus the x axis of pc (right red dot) divided by 2
//pb.x = (pa._x + pc._x)/2;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top