MoveToPoint function

Hello All!

I am currently trying to write a good function that moves and object in 2D space to a specific point (x, y).

The function is as follows:


public function moveTowards(pX, pY):void {
    var dir:int = Math.atan2(pY-y,pX-x)*180/Math.PI;
    x += Math.round(Math.cos(dir*Math.PI/180)*iSpeed);
    y += Math.round(Math.sin(dir*Math.PI/180)*iSpeed);
}

The method is part of a class that is extend from the MovieClip class.

pX and pY are the coordinates to the position where the object has to move to.
iSpeed is a variable that defines the object its speed, for example 5.

The problem with this function is that the destination will never be reached.
There is always a slight difference from the current position to the destination position, resulting in a shaking/vibrating object. The position seems to oscillating or something.

How can I solve this?

What I want is that the object moves in a straight line to the destination. So the x and y speeds are unequal unless both distances are the sameā€¦