
hey guys, this is what i'm trying to do  make the button cling on to the cursor when the cursor is near enough. is it possible?
this is the code i used. i put it in the first frame. it doesn't work though. i might be approaching the problem in an entirely wrong manner.

buAboutUs.onMouseMove = function()
{
homeX = this._x;
homeY = this._y;
yDist = Math.abs(thisX  _xmouse);
xDist = Math.abs(thisY  _ymouse);
dist = yDist/xDist;
if (dist <= 30)
{
buAboutUs._x = _xmouse;
buAboutUs._y = _ymouse;
} else
{
buAboutUs._x = homeX;
buAboutUs._y = homeY;
}
};
oh btw, how does one write code here? the one where the font becomes blue.

by putting [ c o d e ] and [ / c o d e ]

try to put trace("function called") ... to check that function is calling or not ?

hey, thanks for replying! where do i put it? in the function? and where is it supposed to come out?
thanks a bunch

@ starting of your function ... on very 1st line ...

i can't seem to get it
here's the file. it's quite small. around 4kb
http://www.mydestiny.net/~rmmt/send.zip
maybe u guys can take a quick peep?

seen your file ...
i noticed that btn.onMouseMove event is not supported by FlashMX by actionScript ... you can put this code on the button ...
hope this will work

hey there, i put this in the button.
Code:
onMouseMove = function()
{
//trace("function called");
homeX = this._x;
homeY = this._y;
yDist = Math.abs(thisX  _xmouse);
xDist = Math.abs(thisY  _ymouse);
dist = yDist/xDist;
if (dist <= 30)
{
do
{
this._x = _xmouse;
this._y = _ymouse;
} while (dist <= 30);
break;
} else
{
this._x = homeX;
this._y = homeY;
}
};
and also this.onMouseMove
i also tried taking out the whole bracket of on mouse move, but that will not tell the button to do anything.
how about making the stage the listener? i know in java you can make the "canvas" the listener.

thanks for replying aashu (aachoo?) hehe
here is something somewhat similar (but my actionscript will not be anything like this). i just want to stress out the clinging part. but i want my button, instead of going back into position when i move the cursor fast, it goes back into position when the cursor moves too far away from home.
http://www.esu.lt/andrius/10/go.htm

ok ... so now with final solution and tested OK.
Code:
stop();
aashu = new Object();
Mouse.addListener(aashu);
aashu.onMouseMove = function()
{
//trace("function called");
homeX = this._x;
homeY = this._y;
yDist = Math.abs(thisX  _xmouse);
xDist = Math.abs(thisY  _ymouse);
dist = yDist/xDist;
if (dist <= 30)
{
do
{
this._x = _xmouse;
this._y = _ymouse;
} while (dist <= 30);
break;
} else
{
this._x = homeX;
this._y = homeY;
}
};
The Game is Over!

thanks a bunch, but..
i tried putting that code in the first frame but it has errors!
could i have a look at the fla u made?

Another Methodology
Here's another thought... why not try it this way. Put the button into a movie clip, and attach the following code:
Code:
onClipEvent (enterFrame) {
dX = Math.abs(_root._xmouse  this._x);
dY = Math.abs(_root._ymouse  this._y);
distance = Math.sqrt((dX*dX)+(dY*dY));
if (distance <=30) {
this._x = _root._xmouse;
this._y = _root._ymouse;
}
}
Quick run down... dX and dY are the x and y distances between the mouse and the current object ("this"). distance is the actual mathematical distance between the cursor and "this". If that mathematical distance is within a certain parameter (30, in this case), it centers the button on the cursor. This code does not llow for any way to get the button back off the cursor, nor does it provide any way to slowly draw "this" to the cursor, when the mouse is sort of at the edge of that 30 px parameter. I don't know if either of those fit into your project specs.
Best of luck.

Re: thanks a bunch, but..
Originally posted by rmmt
i tried putting that code in the first frame but it has errors!
could i have a look at the fla u made?
actually i not saves FLA for any flashkit problem ... but tell me what error it shows ...

thanks all of you guys, actually, i got it to work i looked at the samples and i read the joystick sample and how it's coded. and i put this in the first frame:
Code:
abtUsX = abtUsMCSpr._x;
abtUsY = abtUsMCSpr._y;
tension = .5;
decay = .5;
_root.onEnterFrame = function()
{
with (abtUsMCSpr)
{
xDist = abtUsX  _root._xmouse;
yDist = abtUsY  _root._ymouse;
xDistSq = Math.pow(xDist, 2);
yDistSq = Math.pow(yDist, 2);
dist = Math.sqrt(yDistSq + xDistSq);
if (dist <= 30)
{
abtUsMCSub._x = _xmouse;
abtUsMCSub._y = _ymouse;
} else
{
leaveXSpeed = abtUsMCSub._x * tension + (leaveXSpeed * decay);
abtUsMCSub._x += leaveXSpeed;
leaveYSpeed = abtUsMCSub._y * tension + (leaveYSpeed * decay);
abtUsMCSub._y += leaveYSpeed;
}
}
}
thanks a lot again!

glad to hear that it's working ...
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
