Copy link to clipboard
Copied
I have an animation I have created and would like to allow the user to scroll up and down (for forwards and backwards) to control which direction the animation plays and at what rate. I'd also like to have the the animation do nothing if the scroll wheel isn't being manipulated. Here's the code I have so far, but I keep getting errors:
import flash.events.MouseEvent;
function handleMouseWheel(event:MouseEvent):void {
trace("The delta value is: " + event.delta);
frame = (clip_mc._currentframe + delta);
clip_mc.gotoAndStop(frame);
}
addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheel);
Appreciate your help!
I'm pretty new to this and I'm not sure what I'm doing wrong.
Thanks
Copy link to clipboard
Copied
If you are getting errors you should show them in your posting.
Assuming you are using AS3, _currentframe is AS2 and will not work with AS3. In AS3 you use currentFrame
delta is undefined, but event.delta might not be
So the line...
frame = (clip_mc._currentframe + delta);
should be...
frame = (clip_mc.currentFrame + event.delta);
Also, the event handler function name should be the same and the name specified by the event listener.
Copy link to clipboard
Copied
Completely forgot to include my errors. After updating the code:
import flash.events.MouseEvent;
function handleMouseWheel(event:MouseEvent):void {
trace("The delta value is: " + event.delta);
frame = (clip_mc.currentFrame + event.delta);
clip_mc.gotoAndStop(frame);
}
addEventListener(MouseEvent.handleMouseWheel,mouseWheel);
And the errors I'm getting: (with my animation playing from beginning to end)
Scene 1, Layer 'Actions', Frame 1, Line 6, Column 2 | 1120: Access of undefined property frame. |
Scene 1, Layer 'Actions', Frame 1, Line 6, Column 11 | 1120: Access of undefined property clip_mc. |
Scene 1, Layer 'Actions', Frame 1, Line 7, Column 6 | 1120: Access of undefined property clip_mc. |
Scene 1, Layer 'Actions', Frame 1, Line 7, Column 26 | 1120: Access of undefined property frame. |
Scene 1, Layer 'Actions', Frame 1, Line 12, Column 29 | 1119: Access of possibly undefined property handleMouseWheel through a reference with static type Class. |
Scene 1, Layer 'Actions', Frame 1, Line 12, Column 46 | 1120: Access of undefined property mouseWheel. |
Apologies for my ignorance. I've been getting into ActionScript and still don't know much at all as I've only touched on programming in the past.
I really appreciate your help.
Thanks again!
Copy link to clipboard
Copied
function handleMouseWheel(event:MouseEvent):void {
trace("The delta value is: " + event.delta);
var frame:int = (clip_mc.currentFrame + event.delta); // variables must be declared
clip_mc.gotoAndStop(frame); // you need to assign the name "clip_mc" to the object on the stage via the Properties panel
}
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
Copy link to clipboard
Copied
Great! These changes have removed all errors except for the clip_mc assignment. Is there a particular object I should assign the name "clip_mc" to?
Because the code affects the entire file and not a single object, I'm not sure where to assign the name.
Sorry! New to Flash and still getting a feel of the environment.
You've been a big help!
Copy link to clipboard
Copied
You cannot target an object if it doesn't exist - you would have to create an instance named clip_mc if you want to target an object named clip_mc. If you are trying to manipulate the same timeline that the code is in then just use...
gotoAndStop(frame)
Copy link to clipboard
Copied
Oh, I see!
I've moved the code around a bit and I'm not getting any errors, but unfortunately, the animation just plays as normal and is unaffected by an scrollwheel input:
function handleMouseWheel(event:MouseEvent):void {
trace("The delta value is: " + event.delta);
var frame:int = (currentFrame + event.delta);
gotoAndStop(frame);
}
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);
(As a side note, this is the only code in my flash file)
Copy link to clipboard
Copied
I've also added:
stop()
at the beginning so that the animation doesn't play automatically.
No errors, but still no response from the scroll wheel.
Copy link to clipboard
Copied
Does anyone know if the there any way we can find the location of the canvas scroll handler?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now