Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
have javascript return the browser width and use the following to convert mouse position to a movieclip frame number:
paramF(mc,0,1,browserwidth,200);
function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void{
mc.m=(y1-y2)/(x1-x2);
mc.b=y1-mc.m*x1;
}
you can then use the following to generate the frame number and direct your movieclip:
mc.gotoAndStop(Math.round((mc.m*xpos+mc.b));
Copy link to clipboard
Copied
I don't have a conversion yet.
Can't figure out how to do the conversion.
If i have to do the same with flash only, i would do this and will have the same effect.:
stop();
function findFrame(event:Event):void{
var frame:int = Math.floor((stage.mouseX/stage.stageWidth) * 100) + 1;
gotoAndStop(frame);
};
addEventListener("enterFrame",findFrame);
But i'm using Java because i'm overlaying my swf with some html and it will not trace my mouse anymore
Copy link to clipboard
Copied
use this:
paramF(mc,0,1,browserwidth,200);
function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void{
mc.m=(y1-y2)/(x1-x2);
mc.b=y1-mc.m*x1;
}
you can then use the following to generate the frame number and direct your movieclip:
mc.gotoAndStop(Math.round((mc.m*xpos+mc.b));
p.s. why are you using javascript for the mouse position?
Copy link to clipboard
Copied
I'm using javascript, because I am overlaying my swf with some div's. And when you overlay your swf, actionscript won't trace you mousemovent anymore.
I can't get your code working, can you maybe paste your code inside mine? maybe i'm doing something wrong
PS: check this out
http://isdekoning.com/qsite/parallax.html
This is what i want to achieve with a full screen animation
Thanks for your help
Copy link to clipboard
Copied
I'm using javascript, ...
You're out of luck then. This is actionscript3 forum.
Copy link to clipboard
Copied
ignore the above message. use:
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;
var m:Number;
var b:Number;
public function Main():void
{
if (ExternalInterface.available)
{
try
{
flash.external.ExternalInterface.addCallback("sendToActionScript", posFromJavaScript);
}
catch (error:Error)
{
trace(error.message);
}
}
}
// call resizeF from js and pass the browser width and height. call this when page loads and stage resizes
private function resizeF(w:int,h:int):void{
paramF(0,1,w,this.totalFrames);
}
private function paramF(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number):void{
m=(y1-y2)/(x1-x2);
b=y1-mc.m*x1;
}
private function posFromJavaScript(xpos:int, ypos:int):void {
xposText.text = String(xpos);
yposText.text = String(ypos);
this.gotoAndStop(Math.round(m*xpos+b));
}
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now