Distance

Can you make Flash calculate distance?

I want Flash to measure the distance between a movie clip “ball” and a mouseDown action. So that the greater the distance, the faster the ball with travel. Then after the ball has passed the spot where I clicked, the ball with naturally slow down, but will do so in reference to how fast the ball was moving, in turn in reference to the distance between the movie clip and the mouse click. I know the code for everything but calculating the distance between the movie clip and click, and returning that distance to effect the speed.

Can anyone help? That would be much appreciated.

I think that I am going to reply to my own message, and ask a new question.

Ok, would the distance equation be:

dx = this._x-_xmouse;
dy = this._y-_ymouse;
?

If this is true, do I put that in the onClipEvent (load) since it is my starting equation? And if I do, what do I put in the (enterFrame) to get Flash to test the distance?

Ugh, maybe I should have thought more before I started posting. Sorry.

lol… It’s tough answering your own questions no? :slight_smile:

I’d say that you’re close to it. Let me think about how I would attempt that effect.

maybe something like this

onClipEvent(load){
function checkClip(){
dx = this._x-_xmouse;
dy = this._y-_ymouse;
}
}
onClipEvent(enterFrame){
checkClip();
}

In this situation, the clip would check the distance every time the clip entered a frame. It doesn’t solve the problem though, of the mouse interaction. I’m still trying to think about how you could do it only on a mouse click, without having an invisible button overlaying the entire project. Like I said… I’m still thinking. :slight_smile:

Ok, I’m not quite getting the exact effect that I wanted, but I think that I’m getting closer, at least in theory…however, I reach a costly error to get to where I am.

Here is what I have if I try to ignore the Distance equation(which I really want to add!!)

onClipEvent (load) {
_x = 0;
_y = 0;
speed = 5;
extra = 100;
}

onClipEvent (mouseDown) {
//make the ball go past the mouse click
EndX = _root._xmouse + extra;
EndY = _root._ymouse + extra;
}

onClipEvent (enterFrame) {
_x += (EndX-_x)/speed;
_y += (EndY-_y)/speed;
}

Now the effect on the first click of the mouse is that the ball goes past the mouse click and seems to slow down from friction. However, when you click again, the ball “wiggs out!”

Nonetheless, I am really no closer than when I started, because I need for the ball to repeat this effect until I tell it not to.

Frustration envelopes MadMax