[FMX] movent with mouse

Hello,

I have a white square(mc) on my stage. In the top left corner of that square is a little arrow. I want that arrow to move along the _y axis when the mouse is moving on the square. So i want the square to move along with the mouse. I like the movement to be easing. Is there somebody to help me?

MovieClip.prototype.easeY = function(y){
 this.onEnterFrame = function(){
 this._y = y-(y-this._y)/1.2
 if(this._y > y-1 && this._y < y+1){
 this._y = y;
 delete this.onEnterFrame;
 }
 }
 }
 _root.onMouseMove = function(){
 square.easeY(_root._ymouse);
 }

Hi Voetsjoeba,

Thank you for your fast reaction. The square is moving, but that’s not what I needed. As I told before. On the square is an little arrow, which I want to move with the mouse. But only when the mouse is on the square. So the arrow have to stay on the square.

Ah ok, your first post confused me a bit, but when reading “So i want the square to move along with the mouse”, I thought that it was the square that eventually had to move with the mouse, not the arrow. Anyway. This is what you could do:


MovieClip.prototype.easeY = function(y){
this.onEnterFrame = function(){
this._y = y-(y-this._y)/1.2
if(this._y > y-1 && this._y < y+1){
this._y = y;
delete this.onEnterFrame;
}
}
}
_root.onMouseMove = function(){
if(this.square.hitTest(this._xmouse,this._ymouse)){
this.square.arrow.easeY(_root._ymouse);
}
}

Hi Voetsjoeba,

It works perfect :thumb: Thank jou :wink:

Geen probleem :wink: