Skip to main content
jakouka
Participant
November 17, 2014
Question

Trying to figure out how to implement the scroll wheel for scrubbing through the final swf animation.

  • November 17, 2014
  • 2 replies
  • 1042 views

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

This topic has been closed for replies.

2 replies

Participant
June 18, 2017

Does anyone know if the there any way we can find the location of the canvas scroll handler?

Ned Murphy
Legend
November 17, 2014

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.

jakouka
jakoukaAuthor
Participant
November 17, 2014

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 21120: Access of undefined property frame.
Scene 1, Layer 'Actions', Frame 1, Line 6, Column 111120: Access of undefined property clip_mc.
Scene 1, Layer 'Actions', Frame 1, Line 7, Column 61120: Access of undefined property clip_mc.
Scene 1, Layer 'Actions', Frame 1, Line 7, Column 261120: Access of undefined property frame.
Scene 1, Layer 'Actions', Frame 1, Line 12, Column 291119: Access of possibly undefined property handleMouseWheel through a reference with static type Class.
Scene 1, Layer 'Actions', Frame 1, Line 12, Column 461120: 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!

Ned Murphy
Legend
November 17, 2014

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);