Can someone please give a simple example of where we could use capture mode rather than bubbling mode for a Flash Player event?
Most of the time we are using bubbling mode and we set useCapture to false (when adding an event listner). What would be the ideal situation to use the capturing phase?
Basically if you want to stop propagation, you should use the capturing phase. For example, you have a default keyboard listener, and you want to cancel that in a rare condition. There are some points when you may want to use the capturing phase, but those can be achieved without it. To understand capturing and bubbling phase, see image below:
Related
Trying to use libgdx's drag listener, I realized that the #cancel method would only be called AFTER #dragStop even if ESC is pressed before the mouse button release, which is practically preventing me from cancelling the action meanwhile.
So how am I supposed to deal with my selection cancellation? With an additional keyboard input listener, perhaps?
So what is the functional point with the cancel method?
Thanks for any lights here.
For now, I'll just be checking up Gdx.input.isKeyPressed(Input.Keys.ESCAPE) at render time, not using #cancel anymore.
Will make this brief, I have a game map with units on it and had finalized a fully interactive minimap where the units on the minimap have event listeners for rollover/rollout (displays a small popup unit data summary) and click (selects the "real" unit on the main game map and scrolls the viewpoint to that location). All done, tested, working.
I then implement an interactive scrollable unit list with more status summary data and dozens of objects with rollover/rollout/click listeners. All tested and working fine.
Then I go back and look at my minimap, and the listeners on the mini-ships aren't working anymore. Things tried:
Debug code to make sure listeners still being added
Debug to watch the one place where I remove those listeners to make sure that ain't happening unexpectedly
Debug to watch all the places I refresh that dialog to make sure every iteration adds the listeners back
Can't see that there is any transparent object on top intercepting
Checked mini-ship parents to make sure I didn't turn off mouseChildren or something like that somewhere
No added stage-level listener, in fact I killed all of them temporarily to test this
What happens when I debug with a breakpoint on the mini-ship listener handler is nada. It's no longer receiving mouse events. So either something I haven't thought of has stopped them from listening or something I don't know of is intercepting.
So what is the strategy here? How can I find the break in the chain?
Well knowing what the actual problem was certainly gives us the advantage of hindsight... that being said, you could have detected the error by adding a trace call inside your function that adds the listener and another one inside your function that removes it. Then you would have seen that it isn't getting re-added. Or you could set break points there.
I'm creating a little developer console for an AS3 AIR application, I'm wanting F12 to add the toggle the display of the console screen but I don't want to litter my program with a bunch of calls to the Console to show or hide it, I also don't really want to be re-creating the console on different screens of my application.
I'm wondering if there's a way or a place I can put my keyboard event to toggle the display that will handle it across the entire application? At the moment I've tried putting it into my Main class which calls the first screen in the hopes that would be able to handle it but as soon as I click on another screen my eventListener isn't called.
Any ideas?
You could add your event listener to FlexGlobals.topLevelApplication instead of specific views, this would achieve the reduction you require
For true application level keyboard handling, attach the listener on the NativeApplication.nativeApplication object.
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, toggleDevConsole,false,0,true);
Attaching the listener to the stage will only work when that particular stage (window) has the focus. This will become an issue if your application has multiple windows that require interaction.
For single window applications, either will work.
Woops, I'm not quite with it today!
For future reference I added the event listener to the Stage in my Main function and it's being picked up every time.
stage.addEventListener(KeyboardEvent.KEY_DOWN, toggleDevConsole, false, 0, true);
I have a little issue related to the events MOUSE_MOVE and TransformGestureEvent.GESTURE_ZOOM.
I want to distinguish both events, when I'm zooming an object MOUSE_MOVE should not act.
In the functions of both events, I start indicating event.stopPropagation(); but no success, so if I press with one finger and move, the MOUSE_MOVE Event should work, but when I press with two fingers, MOUSE_MOVE should not work.
Is there any way that when i could prevent MOUSE_MOVE Event act when I'm Zooming the object?
You could try event.stopImmediatePropagation(). I'm not sure what order the events you are describing fire in, though, so even this may not work. event.preventDefault() may also help.
Docs for it are here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#stopImmediatePropagation%28%29
and here:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/Event.html#preventDefault%28%29
You should be able to check the event.cancelable Boolean property to see if the default behaviour can be prevented or not.
It it possible to catch a double right click event in Actionscript 3?
It is with AIR. You can't capture RIGHT_CLICK in regular AS3, unfortunately.
There is, however, always the possibility of capturing right click events in JavaScript, and using ExternalInterface to call an event handler in the Flash program. See this blog, for example.
Actually you can catch RIGHT_CLICK at the moment :
You need player >11.2
Add additional compiler options -swf-version=19
Use this code :
stage.doubleClickEnabled = true;
stage.addEventListener(MouseEvent.RIGHT_CLICK, handler);
In handler you can save time of previous click, compare with second click and if it`s shorter than 0.5 seconds dispatch your own RIGHT_DOUBLE_CLICK event.