0

If you navigate to the gallery page on this flash site you can see Tintin does as I describe. I have googled a few times but haven't been able to turn up anything. Any help is greatly appreciated, thanks!

EDIT: Although, just changing a symbol's position instead of the current frame would work too. Either way, I just want to know how to do what the link shows.

user1395909
  • 157
  • 1
  • 3
  • 12

1 Answers1

1

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

chq
  • 416
  • 2
  • 5
  • Thanks for this! I think I understand it: at least enough to modify it a little. Here's what I did: ...solveLinearFunction(0,-675,this.stage.stageWidth,300,this.stage.mouseX... { //linear f(x) = mx + b; var mypos:Number = (y1 + y2) / (x1 - x2); var bypos:Number = y1 + (mypos * x1); return (mypos * xx + bypos) * -1; } ... I changed the second number parameter in the function to -675 to center everything up. I then inverted the whole lot by multiplying it by -1. This way I wasn't chasing the content (oh yeah, it was for a gallery so the content needed interaction). – user1395909 Nov 02 '12 at 23:24