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.
Related
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);
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:
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.
I'm creating a DDR-like game for an assignment and my keyboard seems to respond and trace it, but only if I press on the screen with the mouse first.
How can I get rid of that and just have it respond right away?
right_mc is the arrow that's moving
ArrowRight_mc is the arrow at the top
perfect_mc should pop up briefly
and so should a glowing arrow where it hits.
Here is what I have so far:
if(rightDown){
trace("right arrow");
if(right_mc){
if(right_mc.y >= ArrowRight_mc.y){
perfect_mc.visible = true;
glowRight_mc.visible = true;
}
}
}
This has been a long standing issue for Flash developers. Flash needs keyboard focus before it can detect keyboard events.
The problem is that the browser does not give focus to the SWF until the user clicks somewhere inside the SWF. This does make sense though. I don't want the web page I am on to lose focus just because there is a flash movie embedded somewhere. This is a security feature, to stop things like Flash banner ads being silent key loggers. However there are some instances that it makes sense to force the focus e.g. a Flash game where its the only thing on the HTML page.
Usually the best thing to do is have start menu screen with a "play" button. This forces the user to click on the SWF without even knowing about this "focus issue".
There is more info at the Adobe Technote - Giving keyboard focus to an embedded Flash movie.
***EDIT****
Whether the Flash has focus or not, only affects keyboard events. It will not affect code from running, movieclips from playing, or sounds/video from playing.
The issue here is that the embedded SWF file does not have focus when the screen first loads. You can assign focus to it using JavaScript but in my experience, this does not always work 100% of the time because of variations in the way browsers interpret JS. What a lot of people do is have a big START button following the load of the game so that players have to click on the SWF to begin playing. Some sites, even use JS to detect when the game has lost focus and will pause the game and alert the user.
I suppose I haven't exactly answered your question because I'm not that great at JavaScript but I hope this points you in the right direction.
In response to your comment...
I'm unclear on something. If you have to click to start the song then you've already clicked on the SWF and you should be getting keyboard events, right? So if you're having to click to start then click again, maybe you need to make sure your mouse listener is at the root of your display list.
// in your document class / main AS file...
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
Or perhaps you need to poll for input during an EnterFrame loop rather than listen for key events.
I know what you mean. You have a specific object on the stage that needs focus before keyboard events will trigger. I'm having the same issues with a game here. A sprite needs to move with the keyboard arrows but the container needs focus so it will respond. I'm just setting the object I want to move to be tabEnabled as my requirements are only for accessibility purposes so tabbing to the object first will give it keyboard control.