Coordinate space conversion
I'm using Javascript to control a full browser width 200 frame animation on my timeline in flash.
If you are moving your mouse from left to right you can scrub the animation.
The left of the screen is frame 1, the right is frame 200 and the rest is in between
How can i tell flash to show right frame at the right postion on a 100% witdh. For example: x=1200, so flash is showing frame 180.
Sending the coordinates of my mouse to flash is allready working.
Javascript is tracing my mouse and sends the coordinates to flash:
<from name="pos">
X: <input type="text" name="MouseX" value="0" size="4"><br>
Y: <input type="text" name="MouseY" value="0" size="4"><br>
</form>
<script language="JavaScript">
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e)
{
if (IE)
{ // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else
{ // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
document.Pos.MouseX.value = tempX;
document.Pos.MouseY.value = tempY;
//parse coordinates to flash object
swfobject.getObjectById("parallax").sendToActionScript(tempX,tempY);
return true;
}
</script>
And this is my connection to inside flash.
it's sending coordinates to a textfield (It works and i can see the coordinates changing when i move my mouse)
package com.parallax
{
import flash.display.Sprite;
import flash.events.Event;
import flash.external.ExternalInterface;
public class Main extends Sprite
{
var relativeX:Number = 0;
var relativeY:Number = 0;
public function Main():void
{
if (ExternalInterface.available)
{
try
{
flash.external.ExternalInterface.addCallback("sendToActionScript", posFromJavaScript);
}
catch (error:Error)
{
trace(error.message);
}
}
}
private function posFromJavaScript(xpos:int, ypos:int):void
{
xposText.text = String(xpos);
yposText.text = String(ypos);
}
}
}
Thanks
