|
-
anyone else hear that?
Best way to attach clip to middle
I've got a line with several (five for now) points on it and I need to have the user slide the points back & forth along the line...no problem yet...
Now, I've got to have an indicator that stays on the middle point. No problem if I just drag the middle point back and forth between the others, however, if I drag the middle point past one of the points next to it, I need the indicator to stay with the NEW middle point while still dragging the original point.
What would be a good way to determine which point is the "middle?" I was thinking of starting an onEnterFrame to call a function when they startDrag to create an associative array with point number & x value, sort by x value and return the middle value...but it seems like there should be an easier way...
Any ideas??
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
-
Off the top of my head, I'm just not seeing anything easier than what you described ... Maybe some code will fuel someone else's brain...
Code:
stop();
//
var ptAry = [{x:50}, {x:100}, {x:150}, {x:200}, {x:250}];
var numPts = ptAry.length;
var midPt = Math.floor(numPts / 2);
//
for (var i = 0; i < numPts; i++) {
var myPt = attachMovie("pointMC", "p" + i, i, {_x:ptAry[i].x, _y:200});
ptAry[i].ID = myPt;
if (i == midPt) {
myPt.gotoAndStop(2);
}
myPt.onPress = startDragging;
myPt.onRelease = stopDragging;
}
function startDragging() {
this.startDrag(false, 0, this._y, 500, this._y);
this.onEnterFrame = function() {
for (var i = 0; i < numPts; i++) {
ptAry[i].ID.gotoAndStop(1);
if (ptAry[i].ID == this) {
ptAry[i].x = this._x;
}
}
ptAry.sortOn("x", 16);
ptAry[midPt].ID.gotoAndStop(2);
//
};
}
function stopDragging() {
delete this.onEnterFrame;
stopDrag();
}
Last edited by dawsonk; 08-22-2007 at 10:50 AM.
-
anyone else hear that?
Perfect! That's pretty much what I was thinking, but hadn't thought of setting up the dragging as a function and including the location testing in that...very nice!!
Thanks!!!
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
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
|