# From right click problem TO internal setup script (-:

**URL:** https://forum.kirupa.com/t/from-right-click-problem-to-internal-setup-script/74925
**Category:** Uncategorized
**Created:** [January 4, 2005, 6:14am UTC](https://forum.kirupa.com/t/from-right-click-problem-to-internal-setup-script/74925 "2005-01-04T06:14:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![lostchild](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@lostchild](https://forum.kirupa.com/u/lostchild)
#### Post date: [January 4, 2005, 6:14am UTC](https://forum.kirupa.com/t/from-right-click-problem-to-internal-setup-script/74925/1 "2005-01-04T06:14:02Z")

</div>

i was using the following code to detect right click (right mouse down) :

```auto
// mouse down function
**[color=royalblue]_global.[/color]**checkdown = [color=royalblue] **ASnative** [/color](800,2);
[color=red]// check the right mouse down ( can check other mouse buttons as well)
[/color]checkMouse = [color=seagreen] **function** [/color](){
	 [color=red]// left = checkDown(1)
	 // middle = checkDown(4)
	 // right = checkDown(2)[/color]
		right = checkDown(2)
		**[color=seagreen]if[/color]**(right){
			 [color=red]// do stuff here[/color] 
			 **[color=royalblue]trace[/color]**([color=magenta]"right click detected ! ..."[/color])
	 }
}
[color=red]// update on frame enter
[/color][color=royalblue] **_root.onEnterFrame** [/color] = checkMouse;

```

but i dun like to use “onEnterFrame” here which can cause  
performance issues. If this isnt reasonable for u : i dun like it  
to check the statement all the time. not good practice…  
I want to have an event handler like “onRightDown”.  
we can have it but i dun want “onEnterFrame”  
so i tried this one :

```auto
 **[color=royalblue]_global[/color]**.checkdown = [color=royalblue] **ASnative** [/color](800,2); 
[color=seagreen] **var** [/color] skin = {}
checkMouse = **[color=seagreen]function[/color]**(){
right = checkDown(2)
[color=seagreen][color=#000000] [/color] **if** [/color](right){
[color=royalblue][color=#000000] [/color] **trace** [color=#000000]([/color][/color][color=magenta]"right click detected ! ..."[/color][color=#000000])[/color]
	 }
}
**[color=royalblue]Mouse.addListener[/color]**(skin)
skin.**[color=royalblue]onMouseDown[/color]** = checkMouse

```

but it seems, the name “onMouseDown” is fake ![](http://forum.kirupa.com/uploads/kirupa/1003/37ec15b3b4f2a423.gif) coz it just works for the left mouse button. so …the onMouseDown event handler doesnt invoke the “checkMouse” function. Later i found out that ASnative(800,2) is “Key.isDown” method. the following works :

```auto
 checkRight = [color=seagreen] **function** [/color](){ 
[color=seagreen][color=#000000] [/color] **if** [/color](**[color=royalblue]Key.isDown[/color]**(4)){
[color=royalblue][color=#000000] [/color] **trace** [color=#000000]([/color][color=magenta]"right click detected ! ..."[/color][color=#000000])[/color][/color]
	 }
}
**[color=royalblue]_root.onEnterFrame[/color]** = checkRight

```

so we think that we can use the onKeyDown event handler for  
our purpose but we again cant do it. the following code duznt work :

```auto
 **[color=seagreen]var[/color]** skin = {} 
checkRight = function(){
[color=seagreen][color=#000000] [/color] **if** [/color](Key.isDown(4)){
[color=#4169e1][color=#000000] [/color] **trace** [/color][color=#000000]([/color][color=magenta]"right click detected ! ..."[/color][color=#000000])[/color]
	 }
}
**[color=royalblue]Key.addListener[/color]**(skin)
skin.[color=royalblue] **onKeyDown** [/color] = checkRight

```

before asking my main question, we have these stuff :

- ASnative(800,2) is the “Key.isDown” method or the same function that duz the same thing
- So it s acceptable that “onMouseDown” duznt work … maybe internally it s passed to the Mouse object when setting up classes, objects, etc…
- this method ( ASnative(800,2) ) is a plain function that infact duznt belong  
to the Key object internally ( which probably is setup with internal script to belong to )  
Because, otherwise “onKeyDown” would work with the Key object. And i dun know, how to avoid this for the Key object to work …

i m sleepy n i m kinda confused ![](http://forum.kirupa.com/uploads/kirupa/1003/37ec15b3b4f2a423.gif)

- does anyone have an idea or know how this can be set up ?  
i have used AsBroadcaster in some stuff i ve done. So i know about events / event handling / broadcasting …
- i want to know how events r broadcasted internally ? like :  
if we left click the mouse . how does it happen ?

```auto
 [color=red]// when the event occurs :[/color] 
[color=red]/* 1 */[/color] [color=royalblue] **Mouse.broadcastMessage** [/color]([color=magenta]"onMouseDown"[/color])
[color=red]// n this executes the "onMouseDown" function on listeners ?[/color]
[color=red]//or 2 ASnative correspondant function (named "onMouseDown") is fired directly ?[/color]

```

if anyone knows stuff about these, i d really like to know ( the stuff mostly on the compiling level)

cheers…
