Double right click mouse event in AS3? - actionscript-3

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.

Related

libgdx DragListener cancellation

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.

How to detect menu button press in TVOS app using TVJS

I need to know when a document(screen) is popped off the stack in an Apple tvOS app. I thought detecting the Menu button press would be the simplest way, but I'm using TVJS and have not been able to figure out how to write the event handler.
Please help me write an event handler that will fire on document removal, menu button press or offer an alternative solution.
Subscribe to the event unload - it's triggered whenever a page disappears after being popped from the stack:
doc.addEventListener("unload", Presenter.onUnload.bind(Presenter));
[...]
onUnload: function(event) {
console.log("onUnload");
},
There is such thing of a handler for onDocumentRemoval or similar. What you can do, instead, is create a global select handler:
doc.addEventListener("select", self.doThing.bind(self));
And then check if the fired event comes from one of the buttons used to remove an element of the stack (let's suppose those buttons have a class named delete:
doThing: function(event){
var element = event.target;
if (element.getAttribute("class").contains("delete")){
//enter code here
}
EDIT 1:
I found the possible events the TVMLKit handles (I know it is in Swift/Objective-C, but the events are the same):
TVElementTypePlay
A play event has been dispatched.
TVElementTypeSelect
A select event has been dispatched.
TVElementTypeHoldSelect
A hold event has been dispatched.
TVElementTypeHighlight
A highlight event has been dispatched.
TVElementTypeChange
A change event has been dispatched.
Those events are only attachable to a template as far as I could test. I guessed the change event would be perfect if I could attach it to the navigationDocument to listen for changes, but those two options won't work and both fire errors:
Attached to the global:
navigationDocument.addEventListener("change", function(event){console.log(event)});
Attached to the documents array:
navigationDocument.documents.addEventListener("change", function(event){console.log(event)});
There is no built-in method for those above to listen for any change. The event, though, will work on a template listening to internal changes. But it won't fire when the template is pushed to or popped from the stack.
I am guessing you will need to re-design your app in order to achieve what you are looking for.

How do I programmatically play a button animation?

How do I make it look like a button was pressed using C# code? If I can actually push the button (play the animation and activate the events associated with the button press) with code that would be even better.
Playing the animation is pretty easy, using the Visual State Manager:
private async void PretendToClickButton()
{
VisualStateManager.GoToState(myButton, "Pressed", true);
await Task.Delay(250);
VisualStateManager.GoToState(myButton, "Normal", true);
}
You can play with the delay as you see fit.
Programmatically raising the event is not possible; you just have to call the handler method(s) directly (which assumes you the code that handles the event).
[Edit: You could subclass Button and provide your own mechanism for simulating the Click event, but that makes the XAML a wee bit trickier]

How to capture all keyboard input to a custom element?

Here is my problem: I've got a swf loaed inside my loader an in that swf I have a keylistener:
stage.addEventListener(KeyboardEvent.KEY_DOWN, this.__onKeyDown, false, int.MAX_VALUE);
Now I'm adding a TextInput to this stage and I would like this input to catch all keyboard events while I'm focusing it. Is it possible to do so that native __onKeyDown will not fire until my TextInput has lost focus?
Thank you for your answers and sorry for my bad english.
You could give your listener higher priority (which you are), and stopAllPropogation in your handler. I've never tried this with an embedded swf so if it doesn't work right away, you could also try listening to the event in the capture phase (third parameter in addEventListener).
function __onKeyDown(e:KeyboardEvent):void {
e.stopImmediatePropagation();
//rest of you handler code here
}

Simulate mouse click AS3

I'm having trouble simulating a click call to a button(displayObject) thats generated via an API call( youtube as3 API). I have not seen any mention of security reasons as to why I can not simulate a click as long as something is registered with a click handler.
Basically I checked to make sure the button made is listening to a mouse click event with:
trace(generatedButton.hasEventListener(MouseEvent.CLICK)) which returns true
I proceed to than call this:
generatedButton.dispatchEvent( new MouseEvent(MouseEvent.CLICK, true) );
And nothing happens yet if I physically click the button it works. Is there some security measure that prevents something from being fake clicked unless its origin is strictly from the system mouse?
I even set a timeout call on the click function and moved my cursor over the button and let it fire in case it was an issue of the mouse having to over the object but still nothing. I am kind of stumped at this point.
Any help would be appreciated!
Ok well I made a quick FLA and wrote this code and the dispatch Mouse event works perfectly..
import flash.events.MouseEvent;
myButton.addEventListener(MouseEvent.CLICK, myClickHandler);
function myClickHandler(e:MouseEvent):void
{
trace("clicked");
}
setTimeout(function()
{
myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
},2000);
YouTube api must block against something like this
The following code works fine in my local sandbox.
btn.addEventListener( MouseEvent.CLICK, test )
function test( e:Event ):void{
trace('asdf');
}
btn.dispatchEvent( new MouseEvent( MouseEvent.CLICK ) );
So I can only come to 2 conclusions.
First is a security issue. Flash has some security issues with click events triggering the FileReference class where it can only be used if the stack has a user click in it. This issue may carry over to any artificial dispatching of that event. It works in my sandbox because the restriction doesn't apply here.
The second one is you are dispatching the event to soon and the buttons listener hasn't been added to the button from the api.
In this case try calling the dispatch after the stage render event has been called.
stage.addEventListener( Event.RENDER, test )
function test( e:Event ):void{
btn.dispatchEvent( new MouseEvent( MouseEvent.CLICK ) );
}
Just my guess anyway.
instead of doing a dispatchEvent, which will eventually call a method anyway, just call the method and since its expecting a MouseEvent, do yourClickMethod(null)
You can't simulate click events on a server, it is because security issues. Instead of dispatchingEvent you can call method directly. I ll look for the description but its illegal. You can check firefox firebug logs for error description.