Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Nov 16, 2014 Nov 16, 2014

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

TOPICS
ActionScript
982
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 16, 2014 Nov 16, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 16, 2014 Nov 16, 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 16, 2014 Nov 16, 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2014 Nov 17, 2014

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 17, 2014 Nov 17, 2014

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2014 Nov 17, 2014

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2014 Nov 17, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 18, 2017 Jun 18, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines