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

MouseWheel Event not working

Explorer ,
Feb 07, 2013 Feb 07, 2013

Hi I have added a movieClip on stage, I want when It attach to stage then mouseWheel event will fire, it still working but I need to click on stage to active for this.

I want i work automatically without clicking on Stage.

TOPICS
ActionScript
2.6K
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
Guru ,
Feb 07, 2013 Feb 07, 2013

call

stage.focus = stage;

after any MouseEvents are processed

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 ,
Feb 07, 2013 Feb 07, 2013

That is the nature of the plugin. Flash (and many OS's in general) only "activate" once the mouse has clicked on the application.

If you put your wheel listener on the stage you don't ever need to set stage.focus = stage;, the listener will work no matter what object you have selected, unless you explicitly stop propagation. 

This "you must click" nature is present for other events in flash such as the keyboard event. You've probably noticed on many flash games that using keyboard controls won't work until you "click" (activate) the Flash plugin. This is the same thing. Even when testing in the Flash IDE (CTRL+ENTER/CTRL+SHIFT+ENTER). You must click the window to start the events.

Open a new AS3 document to see this example show you that focus of any MovieClip you have on stage doesn't have anything to do with the wheel responding. Just paste this code into frame 1 and test. Until you click the window you shouldn't receive feedback from the wheel. There is a red box. On mouse roll over or click I set focus to the red square, yet the mouse wheel still fires off perfectly fine.

Example:

import flash.display.MovieClip;

import flash.events.MouseEvent;

// global wheel listener

stage.addEventListener(MouseEvent.MOUSE_WHEEL, onWheel);

// function to trace when wheel is spin

function onWheel(e:MouseEvent):void

{

          trace("MouseWheel: " + e.delta);

}

// generate MovieClip (red box)

var box:MovieClip = new MovieClip();

box.graphics.beginFill(0xFF0000,1);

box.graphics.drawRect(50,50,200,200);

box.graphics.endFill();

addChild(box);

// add a listener to the box just to allow focus changes

box.addEventListener(MouseEvent.MOUSE_OVER, focusMe);

box.addEventListener(MouseEvent.CLICK, focusMe);

function focusMe(e:MouseEvent):void

{

          stage.focus = MovieClip(e.target);

}

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
Guru ,
Feb 07, 2013 Feb 07, 2013

It´s deabatable, whether it is "the nature of the plugin".

You must click the window to start the events.

No you don`t and you shouldn`t have to.

Years ago when I had to develop a wep-application for quadruplegic users, who were not able to set the focus in a browser window inside an flex-application I was very grateful to have workarounds like this , that would overcome this problem, and would allow to have keyboard events registering without the need to manually set focus.

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 ,
Feb 07, 2013 Feb 07, 2013

It's the nature of window activation in general.

The proposed workaround is ancient and I never employed it because to my knowledge webkit browsers don't support this.

You can tab around a page and if section 508 is required for you then you should be making sure your tabIndex is set properly. Then simply telling the user to tab to the control isn't difficult when they need to tab to everything else on the site anyhow. Nor would I go down this 1% minority bunnytrail in this conversation unless the OP stipulated this is a concern for their demographic.

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
Explorer ,
Feb 07, 2013 Feb 07, 2013

I tries this on new fla but the problem is same, it's working but I need to click on stage

import flash.events.MouseEvent;

stage.addEventListener(MouseEvent.MOUSE_WHEEL,mw)

stage.focus=this

function mw(event:MouseEvent):void{

    trace('WORKING')

}

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 ,
Feb 08, 2013 Feb 08, 2013
LATEST

Did you try the code I posted above?

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