Use a linear function to calculate all points given the beginning and the end proportions.
In this example, the movieclip myMc
will change its x position based on the cursor given this two pairs: On mouseX = 0
it will be at 100px, and on mouseY = stage.stageWidth
it will be at 300px. Remember this is a linear function, so the proportion continues beyond the given limits!
function onEnterFrame(e:Event){
myMc.x = solveLinearFunction(0, 100, this.stage.stageWidth, 300, this.stage.mouseX);
}
function solveLinearFunction(x1:Number, y1:Number, x2:Number, y2:Number, xx:Number):Number{
//linear f(x) = mx + b;
var mypos:Number = (y1 - y2) / (x1 - x2);
var bypos:Number = y1 - (mypos * x1);
return mypos * xx + bypos;
}
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
Here is some more info on Linear functions, they are quite handy to make scrollbars and paralax scrolling effects: http://earthmath.kennesaw.edu/main_site/review_topics/linear_functions.htm