disabling context menu and mouse in Flash - actionscript-3

This should be pretty straight forward.
this should do the trick
stage.removeEventListener(MouseEvent.RIGHT_CLICK, function(e:MouseEvent):void{});
Mouse.hide();
and when I run it in the standalone player it works.
However when I run it in a browser, the right-click menu shows up again. I've tried setting the param wmode="opaque", which removes context menu (independent of the code), but shows the mouse despite the css setting: cursor: none;
is there a another listener that calls the context menu that can be disabled?

To disable the context menu ( and the right click ), you can use MouseEvent.RIGHT_CLICK and / or MouseEvent.CONTEXT_MENU ( available from Flash Player 11.2 and up ) :
stage.addEventListener(MouseEvent.RIGHT_CLICK, function(e:MouseEvent):void {});
stage.addEventListener(MouseEvent.CONTEXT_MENU, function(e:MouseEvent):void {});
Mouse.hide();
Hope that can help.

Related

Projector remote control - control Flash presentation

please can somebody tell me how remote control works? I have to create presentation in Flash platform using ActionScript 3. How to listen keys from remote control to show next slide, prev slide, pause, play etc? Is it like normal keys?
thanks for info
Generally projector remote controls are just left and right mouse click signals. LMB is the 'next slide', RMB is the 'previous slide'.
You're going to run into problems though, since right clicks in Flash open the context menu. Flash isn't really well suited for this purpose as you can see.
I recommend adding your Flash files into a PowerPoint presentation to save yourself all the stress of second-guessing which hardware is available to you.
When programming your flash presentation for use with a remote clicker, do not target left and right mouse clicks.
Instead you need to use keyboard events to target Page Up and Page Down.
The event listener that emulates the remote clicker's forward arrow is:
stage.addEventListener(KeyboardEvent.KEY_DOWN, forwardsFunction);
function forwardsFunction(event:KeyboardEvent):void {
var myKey = event.keyCode;
if (myKey == Keyboard.PAGE_DOWN)
{
The event listener that emulates the remote clicker's backward arrow is:
stage.addEventListener(KeyboardEvent.KEY_DOWN, backwardsFunction);
function backwardsFunction(event:KeyboardEvent):void {
var myKey = event.keyCode;
if (myKey == Keyboard.PAGE_UP)
{
This will allow you to use a remote clicker to work with your Flash presentations. At least this is the case with the Logitech remote I have tested.
Also, I found it necessary to determine the focus for this to work. My Actions were placed on a frame at stage level, ie they related to movieclips placed on the stage. Adding this code to the start of my Actions enabled this to work:
stage.focus=stage;

Kinetics JS "Click" or simple "Touch" event for Mobile device

I am using kinetic-v4.3.0-beta2.js
I want to handle mobile touch event on group for ios & android.
I am binding event such as following
group.on('touchstart', function (evt) {
$('#onpopMenu').popup("open", { x: leftPosition, y: topPosition });
});
I tried 'touchend', 'touchstart' and 'tap'
Got partial success in "Tap" but in that case, shape is draggable so tap event is not properly fire because object will move from it's place.
but if shape is not draggable then it will work fine.
I tried 'touchend' and 'touchstart' event also but popup menu is close after event fire in iOs and android as I am opening Jquery Mobile Popup by Touching group!
The popup menu will only open for 2-3 seconds when the touchstart event fired.
Anyone faced the same problem with kinetic JS Mobile events? How to handle only "Click" or "Touch" event with it.
I checked this http://www.html5canvastutorials.com/kineticjs/html5-canvas-mobile-events/ for reference but had no luck!
I am developing application with Phonegap + JQM + Kinetics JS
Thanks in advance!
Keep in mind that your application is running inside a webview. This is why you've got these 2/3 seconds of delay on touch/click event.
This is why in all my PhoneGap dev, I use Fastclick.js. FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers. The aim is to make your application feel less laggy and more responsive while avoiding any interference with your current logic.
You can find it here https://github.com/ftlabs/fastclick.
It's easy to use (if you're using jQuery) :
<script type='application/javascript' src='/path/to/fastclick.js'></script>
<script>
$(function() {
FastClick.attach(document.body);
});
</script>
I made a jsfiddle for you to test out the click/touch events.
From what I understand, you have a Kinetic.Group node that is draggable but you want to open up a popup using jquery mobile.
You are right that when you drag an object, the tap event does not fire. But you said otherwise the tap event works fine if the shape is not draggable. This leads me to believe:
You want a popup on "tap"
You want a popup on "dragend"
If so, all you need is to use both events like this:
group.on('tap dragend', function (evt) {
$('#onpopMenu').popup("open", { x: leftPosition, y: topPosition });
});
Please let me know if my assumptions are wrong, and I can work with you to get the right solution. I am guessing when you want to popup, so if you let me know exactly when you want a popup to occur that will help a lot.
You might want to also look into using evt.cancelBubble = true; http://www.html5canvastutorials.com/kineticjs/html5-canvas-cancel-event-bubble-propagation-with-kineticjs/

detect when the client focus leave the window

i saw some online flash games can do this:
when you switch your current web to other windows or other web tabs, the application program will draw a black block and tell you've leave the application, click on the flash area to resume .
i've tried some event like focus in and out or mouse leave on the stage,but the reaction isn't what i expected.maybe i use them in the wrong way .please tell me if you got the solution.
var count:int = 0;
this.stage.addEventListener(Event.MOUSE_LEAVE,function(e:Event):void
{
//only be called if your mouse cursor leave the area,but can't detect whether you're actually switch to other program.
trace('mouseleave',count++);
});
this.stage.addEventListener(FocusEvent.FOCUS_OUT,function(e:Event):void
{
//no reaction
trace('focus out',count++);
});
this.stage.addEventListener(MouseEvent.ROLL_OVER,function(e:Event):void
{
//no reaction
trace('mouseenter',count++);
});
There are two methods:
Use Event.ACTIVATE event. But a swf should be on focus before.
Use JavaScript call from ActionScript to check is a window or a tab on focus.

How can I configure modal popups to block MouseEvent.CLICK on AIR mobile?

Using AIR 3.1 and testing with both the (desktop AIR) simulator and a Nook Tablet (running Android 2.3).
I'm using the following code to add a modal popup…
PopUpManager.addPopUp( popUp, FlexGlobals.topLevelApplication as DisplayObject, true );
For the web and Desktop versions of AIR, the above code prevents buttons or other things that are under/behind the modal popup from being clickable.
On AIR mobile however, buttons can be clicked behind the modal blocker.
I also tried to create my own modal blocker by adding a 100% width/height UIComponent to the top level application and then displaying my popup on top of that.
I drew a partially transparent rect into the "blocker" UIComponent's graphics object and then I added a MouseEvent.CLICK listener to it as so:
blocker.addEventListener( MouseEvent.CLICK, onMouseClick, true, int.MAX_VALUE );
// Then my handler looked like this
private function onMouseClick( event:Event ):void {
event.stopImmediatePropagation();
}
I tried useCapture values of both TRUE and FALSE but the behavior I saw on the Nook stayed the same. I was able to click on buttons that were underneath of my modal blocker.
What am I missing here? Something obvious that I'm overlooking?
You could try adding a Mouse_Down or click listener to the stage, then stopping it's propagation if the target isn't a descendant of your popup.
stage.addEventListener(MouseEvent.CLICK,blockClick,true,int.MAX_VALUE,true);
function blockClick(e:MouseEvent):void {
var curTarget:DisplayObject = e.target as DisplayObject;
while(curTarget){
if(curTarget == popup) return;
curTarget = curTarget.parent;
}
e.stopImmediatePropagation();
}

Approaches to replace cursor in pure AS3 / Flare project?

I've got a pure AS3 (no Flex) project that uses Flare to display and interact with a data visualization. I just implemented some panning behavior, so you can click and drag the visualization around, and now I'd like to give the user a visual indicator that this is possible, by switching the arrow cursor with a nice grabby-looking hand icon.
The user can click and drag at any time except when the mouse is over a clickable node (at which time the cursor swaps to a pointer - this behavior is already in place).
So...
1) Do I need to create my own custom bitmap/sprite or is there a palette of built-in cursors I can use? (I'm not using Flex.)
2) Is there a way to simply replace the default arrow with the pan cursor project-wide, or do I need to attach the swapping to mouse events on display objects? Can I use the stage object to make this behavior apply everywhere?
3) How do I perform the swap? Do I use the Cursor object directly or do I need to get involved with the CursorManager?
Any guidance, pseudo-code, or words of wisdom is greatly appreciated!
I don't think there's a CursorManger in flash, only flex. The way i'm doing is with a custom class which hides the cursor and drags the customized cursor at mouse_move. You have to set it to mouseChildren=false, otherwise will flickr or the buttons will not be clickable. One problem i found is with custom contextual menus. Try this link http://abrahamyan.com/2009/03/23/as3-cursormanager/
A few things I learned (all pretty newby, really). Firstly, there are some built-in cursor options you can set by setting Mouse.cursor to any of the options of MouseCursor.TYPE. The Mouse object is a singleton available app-wide, so anywhere you change it in your code, the change persists until another change is triggered.
For my simple case, I did this:
//on init, start with the "hand"
Mouse.cursor = MouseCursor.HAND;
//on clickable items, change to "pointer", then back to "hand"
myClickableNode.addEventListener(MouseEvent.ROLL_OVER, function(evt:Event):void {
Mouse.cursor = MouseCursor.BUTTON;
});
myClickableNode.addEventListener(MouseEvent.ROLL_OUT, function(evt:Event):void {
Mouse.cursor = MouseCursor.HAND;
});
The result is you always have the "hand" until you rollover something clickable, then you get the "pointer".