Copy link to clipboard
Copied
I am trying to create 3D rotate turntable animation where I can click and drag left and right over the image of a product in order to rotate it. It's not a 3D object but more of clicking and scrubbing through a movie clip/images of the product from different angles. When I run the test on a browser it seems to work fine but when I run it on animate as .swf it will not rotate smoothly and give me the error below:
mouseDown
ArgumentError: Error #2109: Frame label 3.0500000000000043 not found in scene 3.0500000000000043.
at flash.display::MovieClip/gotoAndStop()
at dispenser_rotate8_fla::MainTimeline/onMouseMove()
ArgumentError: Error #2109: Frame label 4.050000000000004 not found in scene 4.050000000000004.
at flash.display::MovieClip/gotoAndStop()
......and so on
My goal is to make something like this: https://petchatz.com/
Below is my code:
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var startX: Number;
var startFrame: Number;
var changeDistance: Number;
var travelDistance: Number;
movieClip.stop();
movieClip.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
movieClip.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
function onMouseDown(event: MouseEvent): void {
trace("mouseDown");
startX = movieClip.mouseX;
startFrame = movieClip.currentFrame;
movieClip.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
//"movieClip" is the instance name of my movieclip
function onMouseUp(event: MouseEvent): void {
trace("mouseUp");
movieClip.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
function onMouseMove(event:MouseEvent): void {
changeDistance = movieClip.mouseX - startX;
travelDistance = startFrame + changeDistance;
if (travelDistance > movieClip.totalFrames) {
movieClip.gotoAndStop (travelDistance % movieClip.totalFrames);
} else if (travelDistance < 0) {
movieClip.gotoAndStop (movieClip.totalFrames + (travelDistance % movieClip.totalFrames));
} else {
movieClip.gotoAndStop (travelDistance);
}
}
I am very new to Animate and AS3 so any help would be much appreciated. Thanks!
I think you're using the debug version of Flash Player, and that's showing you errors that the non-debug version is hiding. The main error is that frames are whole numbers, and you're attempting to go to frame 3.0500000000000043. Changing this line would fix that:
changeDistance = Math.round(movieClip.mouseX - startX);
But, there is a different approach you could be taking. You can use atan2() to work out the angle of one point from another, and with that you could check the angle the user starts
...Copy link to clipboard
Copied
I think you're using the debug version of Flash Player, and that's showing you errors that the non-debug version is hiding. The main error is that frames are whole numbers, and you're attempting to go to frame 3.0500000000000043. Changing this line would fix that:
changeDistance = Math.round(movieClip.mouseX - startX);
But, there is a different approach you could be taking. You can use atan2() to work out the angle of one point from another, and with that you could check the angle the user starts to drag from, and on mouse move check the angle they are at now. The calculations are in radians, and so one rotation is about 6.283. If you made a 628 frame rotation of the object you could take the angle from the mouse down, make a note of the current frame number, then on mouse move you add 100 * the angle change to the frame number.
There would still be some checking to see if you're past the totalframes or below zero, but those are things you're doing already.
Here's the arithmetic for know the angle, assuming the x and y of your movieclip are in its center ('e' would be the mouse event):
var dx:Number = e.stageX - mc.x;
var dy:Number = e.stageY - mc.y;
var ang:Number = Math.atan2(dy,dx);
Copy link to clipboard
Copied
Ah that makes more sense. I've changed that line of code and it works perfectly. I can't thank you enough! I have been struggling with this issue for a while now.
Below is the final code:
import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var startX: Number;
var startFrame: Number;
var changeDistance: Number;
var travelDistance: Number;
movieClip.stop();
movieClip.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
movieClip.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
function onMouseDown(event: MouseEvent): void {
trace("mouseDown");
startX = movieClip.mouseX;
startFrame = movieClip.currentFrame;
movieClip.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
function onMouseUp(event: MouseEvent): void {
trace("mouseUp");
movieClip.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
}
function onMouseMove(event:MouseEvent): void {
changeDistance = Math.round(movieClip.mouseX - startX);
travelDistance = startFrame + changeDistance;
if (travelDistance > movieClip.totalFrames) {
movieClip.gotoAndStop (travelDistance % movieClip.totalFrames);
} else if (travelDistance < 0) {
movieClip.gotoAndStop (movieClip.totalFrames + (travelDistance % movieClip.totalFrames));
} else {
movieClip.gotoAndStop (travelDistance);
}
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now