Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rating: Thread Rating: 7 votes, 5.00 average. Display Modes
Old 07-27-2009, 02:36 PM   #1
Number0
Member
 
Join Date: Apr 2009
Posts: 84
Default Is there anyway to disable the left and right mouse clicks?

Is there anyway to disable the left and right mouse clicks?
Number0 is offline   Reply With Quote
Old 07-27-2009, 02:51 PM   #2
untitled88
Registered User
 
Join Date: Jun 2009
Posts: 35
Default

This should help:
http://www.uza.lt/blog/2007/08/solve...-click-in-as3/
untitled88 is offline   Reply With Quote
Old 07-27-2009, 03:44 PM   #3
Number0
Member
 
Join Date: Apr 2009
Posts: 84
Default

it didn't help.
Number0 is offline   Reply With Quote
Old 07-27-2009, 05:34 PM   #4
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,866
Send a message via Skype™ to henke37
Default

You can ignore the left clicks as much as you want, but the context menu is not possible to remove.
henke37 is offline   Reply With Quote
Old 07-27-2009, 06:45 PM   #5
rondog
ActiveDen.net/user/rondog
 
rondog's Avatar
 
Join Date: May 2006
Location: San Diego
Posts: 579
Default

Quote:
Originally Posted by henke37 View Post
You can ignore the left clicks as much as you want, but the context menu is not possible to remove.
According to untitled88's post it is possible. Check out the demo.
__________________
My activeden portfolio
My website
rondog is offline   Reply With Quote
Old 07-27-2009, 07:34 PM   #6
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Quote:
Originally Posted by mrwicked View Post
According to untitled88's post it is possible. Check out the demo.
Yeah, using javascript you can intercept the right click, stop flash from hearing it, and then call a method through the ExternalInterface telling flash independently that it occurred.

What it does lack though is right click for specific objects and flow through the event pool. It fires globally across the entire app.

You could code up a class that would give the same functionality as left click though.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!
lordofduct is offline   Reply With Quote
Old 07-27-2009, 09:50 PM   #7
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

I got bored today so I rewrote that script found at the link "untitled88" posted, and added in some extra features.

-> it handles RIGHT_MOUSE_DOWN, RIGHT_MOUSE_UP, and RIGHT_CLICK
-> the event is captured by a Singleton and then dispatched into the event pool just like any other MouseEvent
-> it is dispatched AS A MouseEvent and bubbles through the DisplayList
-> it supports "mouseEnabled" and "mouseChildren"

Here is the JSScript:

Code:
/**
 * LoDRightMouseButtonTrap - written by Dylan Engelman a.k.a LordOfDuct
 * 
 * This class is an expansion on a previous script written by "Uza" at:
 * 
 * http://www.uza.lt/blog/2007/08/solved-right-click-in-as3/
 */

var LoDRightMouseButtonTrap = {
	
	init: function (objId,contId) {
		this.objectId = objId;
		this.containerId = contId;
		this.cache = this.objectId;
		
		if(window.addEventListener){
			 window.addEventListener("mousedown", this.onGeckoMouseDown(), true);
			 window.addEventListener("mouseup", this.onGeckoMouseUp(), true);
			 
		} else {
			document.getElementById(this.containerId).onmouseup = this.onIEMouseUp;
			document.oncontextmenu = function(){ if(window.event.srcElement.id == LoDRightMouseButtonTrap.objectId) { return false; } else { LoDRightMouseButtonTrap.cache = "nan"; }}
			document.getElementById(this.containerId).onmousedown = this.onIEMouseDown;
		}
	},
	
	deinit: function () {
		if(window.RemoveEventListener){
			//alert('Un init is called for GECKO' );
			window.addEventListener("mousedown", null, true);
			window.RemoveEventListener("mousedown",this.onGeckoMouseDown(),true);
			window.addEventListener("mouseup", null, true);
			window.RemoveEventListener("mouseup", this.onGeckoMouseUp(), true);
		} else {
			//alert('Un init is called for IE' );							
			document.getElementById(this.FlashContainerID).onmouseup = "" ;
			document.oncontextmenu = "";
			document.getElementById(this.FlashContainerID).onmousedown = "";
		}
		
		this.objectId = null;
		this.containerId = null;
		this.cache = null;
	},
	
	killEvents: function(eventObject) {
		if(eventObject) {
			if (eventObject.stopPropagation) eventObject.stopPropagation();
			if (eventObject.preventDefault) eventObject.preventDefault();
			if (eventObject.preventCapture) eventObject.preventCapture();
	   		if (eventObject.preventBubble) eventObject.preventBubble();
		}
	},
	
	call: function(type) {
		document.getElementById(this.objectId).rightMouseButtonTrap(type);
	},
	
	/**
	 * Event Listeners for Gecko style capture.
	 * 
	 * Support for non-IE browsers
	 */
	onGeckoMouseDown: function (e) {
		return function(e) {
			if (e.button != 0) {
				LoDRightMouseButtonTrap.killEvents(e);
				if(e.target.id == LoDRightMouseButtonTrap.objectId && LoDRightMouseButtonTrap.cache == LoDRightMouseButtonTrap.objectId) {
					LoDRightMouseButtonTrap.call("mousedown");
				}
				LoDRightMouseButtonTrap.cache = e.target.id;
			}
		}
	},
	
	onGeckoMouseUp: function (e) {
		return function(e) {
			if (e.button != 0) {
				LoDRightMouseButtonTrap.killEvents(e);
				if(e.target.id == LoDRightMouseButtonTrap.objectId && LoDRightMouseButtonTrap.cache == LoDRightMouseButtonTrap.objectId) {
					LoDRightMouseButtonTrap.call("mouseup");
				}
				LoDRightMouseButtonTrap.cache = e.target.id;
			}
		}
	},
	
	/**
	 * Event Listeners for IE style capture
	 * 
	 * Support for IE browsers
	 */
	onIEMouseDown: function () {
		if (event.button > 1) {
			if(window.event.srcElement.id == LoDRightMouseButtonTrap.objectId && LoDRightMouseButtonTrap.cache == LoDRightMouseButtonTrap.objectId) {
				LoDRightMouseButtonTrap.call("mousedown"); 
			}
			document.getElementById(LoDRightMouseButtonTrap.containerId).setCapture();
			if(window.event.srcElement.id) {
				LoDRightMouseButtonTrap.cache = window.event.srcElement.id;
			}
		}
	},
	
	onIEMouseUp: function () {
		document.getElementById(LoDRightMouseButtonTrap.containerId).releaseCapture();
		if (event.button > 1) {
			if(window.event.srcElement.id == LoDRightMouseButtonTrap.objectId && LoDRightMouseButtonTrap.cache == LoDRightMouseButtonTrap.objectId) {
				LoDRightMouseButtonTrap.call("mouseup");
			}
			
			if(window.event.srcElement.id) {
				LoDRightMouseButtonTrap.cache = window.event.srcElement.id;
			}
		}
	},
}
and here is the Singleton

ActionScript Code:
/**  * RightClickManager - written by Dylan Engelman a.k.a LordOfDuct  *  * Singleton Class written and devised for the LoDGameLibrary. The use of this code  * is hereby granted to any user at their own risk. No promises or guarantees  * are made by the author. Use at your own risk.  *  * This class is intended to be used along with the JavaScript object: LoDRightMouseButtonTrap  *  */ package com.lordofduct.ui {     import com.lordofduct.util.Assertions;     import com.lordofduct.util.SingletonEnforcer;         import flash.display.DisplayObjectContainer;     import flash.display.InteractiveObject;     import flash.display.Stage;     import flash.events.Event;     import flash.events.MouseEvent;     import flash.external.ExternalInterface;     import flash.geom.Point;         public class RightClickManager     {         private static var _inst:RightClickManager;                 public static function get instance():RightClickManager         {             if (!_inst) _inst = SingletonEnforcer.gi(RightClickManager);                         return _inst;         }                 public function RightClickManager()         {             SingletonEnforcer.assertSingle(RightClickManager);         } /**  * Static Members  */         public static const RIGHT_MOUSE_DOWN:String = "rightMouseDown";         public static const RIGHT_MOUSE_UP:String = "rightMouseUp";         public static const RIGHT_CLICK:String = "rightClick"; /**  * Class Definition  */         private var _stage:Stage;         private var _recentDown:InteractiveObject;                 public function start( stg:Stage ):Boolean         {             //if(!stg) throw new Error("com.lordofduct.ui::RightClickManager - stage reference must be non-null.");             Assertions.instance.notNil( stg, "com.lordofduct.ui::RightClickManager - stage reference must be non-null." );                         _stage = stg;                         if (ExternalInterface.available)             {                 ExternalInterface.addCallback( "rightMouseButtonTrap", handleExternalTrap );                 return true;             }             else             {                 trace( "com.lordofduct.ui::RightClickManager - ExternalInterface is not available");                 return false;             }         }             /**      * External Traps      */         private function handleExternalTrap(type:String=null):void         {             var targ:InteractiveObject = trapTopMostChild();             type = type.toLowerCase();                         switch(type)             {                 case "mousedown" : forceMouseDown( targ ); break;                 case "mouseup" : forceMouseUp( targ ); break;             }         }             /**      * Force Events      */         private function forceMouseDown( targ:InteractiveObject ):void         {             if (!targ) return;                         var type:String = RIGHT_MOUSE_DOWN;             var bubbles:Boolean = true;             var cancelable:Boolean = false;             var localX:Number = targ.mouseX;             var localY:Number = targ.mouseY;             var relatedObject:InteractiveObject = targ;             var ctrlKey:Boolean = false;             var altKey:Boolean = false;             var shiftKey:Boolean = false;             var buttonDown:Boolean = true;             var delta:int = 0;                         var evt:MouseEvent = new MouseEvent( type, bubbles, cancelable, localX, localY, relatedObject, ctrlKey, altKey, shiftKey, buttonDown, delta );             targ.dispatchEvent( evt );                         //set the most recent object to have mouse down done             _recentDown = targ;         }                 private function forceMouseUp( targ:InteractiveObject ):void         {             if (!targ) return;                         var type:String = RIGHT_MOUSE_UP;             var bubbles:Boolean = true;             var cancelable:Boolean = false;             var localX:Number = targ.mouseX;             var localY:Number = targ.mouseY;             var relatedObject:InteractiveObject = targ;             var ctrlKey:Boolean = false;             var altKey:Boolean = false;             var shiftKey:Boolean = false;                         var evt:MouseEvent = new MouseEvent( type, bubbles, cancelable, localX, localY, relatedObject, ctrlKey, altKey, shiftKey );             targ.dispatchEvent( evt );                         //if target was the last mouse down, then dispatch click             if( targ == _recentDown) forceMouseClick(targ);             _recentDown = null;         }                 private function forceMouseClick( targ:InteractiveObject ):void         {             if (!targ) return;                         var type:String = RIGHT_CLICK;             var bubbles:Boolean = true;             var cancelable:Boolean = false;             var localX:Number = targ.mouseX;             var localY:Number = targ.mouseY;             var relatedObject:InteractiveObject = targ;             var ctrlKey:Boolean = false;             var altKey:Boolean = false;             var shiftKey:Boolean = false;                         var evt:MouseEvent = new MouseEvent( type, bubbles, cancelable, localX, localY, relatedObject, ctrlKey, altKey, shiftKey );             targ.dispatchEvent( evt );         }             /**      * Basic parent algorithms      */         private function trapTopMostChild():InteractiveObject         {            //get all children under right click             var ms:Point = new Point( _stage.mouseX, _stage.mouseY );             var arr:Array = _stage.getObjectsUnderPoint( ms );                         //if no children stop             if (!arr.length) return;                         //find the top most child that is an InteractiveObject AND is mouseEnabled             var targ:InteractiveObject;             while( arr.length )             {                 targ = arr.pop() as InteractiveObject;                 if (targ && targ.mouseEnabled && notMouseCancelledByParent(targ))                 {                     return targ;                 }             }                         return _stage;         }         private function notMouseCancelledByParent( child:InteractiveObject ):Boolean         {             var par:DisplayObjectContainer = child.parent;                         while(par)             {                 if (!par.mouseChildren) return false;                 par = par.parent;             }                         return true;         }     } }

I'll post shortly with an example of it running

Last edited by lordofduct; 07-27-2009 at 10:42 PM.
lordofduct is offline   Reply With Quote
Old 07-27-2009, 09:55 PM   #8
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Here's the example:

http://www.lordofduct.com/assets/flash/test/test2.html

I tested it on Linux with Firefox 3, Windows with Firefox 3. [edit] just tried IE and it failed... gotta check that out


And this is the DocumentClass for said swf and the html source showing how it's used:

DocumentClass:
ActionScript Code:
package {     import com.lordofduct.ui.RightClickManager;         import flash.display.Sprite;     import flash.events.EventDispatcher;     import flash.events.MouseEvent;     import flash.geom.Point;     import flash.text.TextField;         [SWF(width="800", height="600", backgroundColor="#FFFFFF")]     public class test extends Sprite     {         private var _tf:TextField = new TextField();                 public function test()         {             _tf.multiline = true;             _tf.x = 400;             _tf.y = 500;             this.addChild(_tf);                         var spr:Sprite = new Sprite();             spr.name = "spr";             this.addChild( spr );                         var child1:ClassA = new ClassA();             child1.name = "child1";             spr.addChild(child1);                         var child2:ClassA = new ClassA();             child2.name = "child2";             child2.x = child2.y = 50;             spr.addChild(child2);                         var child3:ClassA = new ClassA();             var spr2:Sprite = new Sprite();             child3.name = "child3";             spr2.name = "spr2";             spr2.addChild(child3);             spr.addChild(spr2);             spr2.x = spr2.y = 25;                         var arr:Array = this.stage.getObjectsUnderPoint( new Point( 60,60) );             var disp:EventDispatcher = arr.pop();                         if(RightClickManager.instance.start(stage)) txtTrace("started");             else txtTrace("failed");                         this.addEventListener(RightClickManager.RIGHT_CLICK, handler );             this.addEventListener(RightClickManager.RIGHT_MOUSE_DOWN, handler );             this.addEventListener(RightClickManager.RIGHT_MOUSE_UP, handler );         }                 private function handler(e:MouseEvent):void         {             txtTrace(e.type + " : " + e.target.name);         }                 private function txtTrace( value:String="default" ):void         {             _tf.htmlText += value + "<br />";             _tf.autoSize = "left";             _tf.y = 500 - _tf.height;         }     } }

and ClassA is just a simple square:

ActionScript Code:
package {     import flash.display.Sprite;         public dynamic class ClassA extends Sprite     {         public function ClassA()         {             this.graphics.beginFill(0xAA0000);             this.graphics.lineStyle(2,0);             this.graphics.drawRect(0,0,100,100);             this.graphics.endFill();         }     } }


Finally the html embedding:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RIGHT CLICK DEMO / AS3</title>

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript" src="LoDRightMouseButtonTrap.js"></script>
</head>

<body onload="LoDRightMouseButtonTrap.init('test','flashcontent');">
	<div id="flashcontent">&nbsp;</div>
	<script type="text/javascript">
	   var so = new SWFObject("test.swf", "test", "800", "600", "9", "#CCCCCC");
		so.addParam("quality", "high");
		so.addParam("name", "test");
		so.addParam("id", "test");
		so.addParam("AllowScriptAccess", "always");
		so.addParam("wmode", "opaque");
		so.addParam("menu", "false");
		so.addVariable("variable1", "value1");
		so.write("flashcontent");
	</script>
</body>
</html>
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!

Last edited by lordofduct; 07-27-2009 at 10:09 PM.
lordofduct is offline   Reply With Quote
Old 07-28-2009, 04:42 PM   #9
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,866
Send a message via Skype™ to henke37
Default

Are you sure that class works as intended? I can't test it, but to me it looks like it would fail if you right click on a display object that is not mouse enabled. See, the container for that object should get the event instead. Also, as far as I know, you can't make the player bubble an event that you dispatch, you have to do that yourself.
henke37 is offline   Reply With Quote
Old 07-28-2009, 07:42 PM   #10
lordofduct
Senior Member
 
lordofduct's Avatar
 
Join Date: Feb 2008
Location: West Palm Beach, FL
Posts: 3,872
Default

Quote:
Originally Posted by henke37 View Post
Are you sure that class works as intended? I can't test it, but to me it looks like it would fail if you right click on a display object that is not mouse enabled. See, the container for that object should get the event instead. Also, as far as I know, you can't make the player bubble an event that you dispatch, you have to do that yourself.
The array returned by "getObjectsUnderPoint" fills the array where the 0 slot is the very lowest object in the DisplayList, while the last object is the top most inside the DisplayObjectContainer used (Grandchildren included). So by popping and checking mouseEnabled, tossing it away if it isn't mouseEnabled, and then popping again will give the top most displayObject that is under that point and is mouseEnabled.

Though there may be some things I'm ignorant about with that returned array, and I'm still working on... must debug of course. Of which it appears I am leaving out some parents in the algorithm, I think I'll fix that today.




Secondly, YES, you can make events bubble through the DisplayList... that's what the "bubble" param of the Event is:

Event( type:String, bubbles:Boolean, cancelable:Boolean)

It can only bubble through the DisplayList... which means it bubbles through the succession of parents of a DisplayObject... if it isn't a DisplayObject dispatching the event, then it doesn't.

Proof of this can be seen if you are using Firefox and you run my demo. It works, yet I'm listening to the instance of the DocumentClass for the MouseEvent, and it gets trapped... thusly bubbling must be working.
__________________
www.lordofduct.com - come read my blog!

If you want to know how to program, take a math class, take a lot of math classes!

Last edited by lordofduct; 07-28-2009 at 08:04 PM.
lordofduct is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:28 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.