Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Right click

Status
Not open for further replies.

doive

Programmer
Jan 7, 2005
4
GB
Hi Guys,

I have a training application written in flash that needs to listen for a right click. I have not seen any way of doing this previously, but have had a few thoughts.

I would like to have a way of disabling menus and of sending a notification of a right click to the flash app. However i have not seen any way of doing this.

On a tangent, would it be possible to disable right clicks on the html page with javascript and then listen for the click with javascript and then send the details of the click to the application?

All help is much appreciated as i am not terribly clued up on flash.

Cheers,

Dave,
 
for button with instance name myButton...code on main timeline


setInterval(function(){if(Mouse.rightMouseDown^(Mouse.rightMouseDown=Key.isDown(2))) Mouse.rightMouseDown ? Mouse.broadcastMessage("onRightMouseDown") : Mouse.broadcastMessage("onRightMouseUp");},40);

Mouse.addListener(myButton);
myButton.onRightMouseDown = function(){
trace("Right Mouse Button Pressed");
}
myButton.onRightMouseUp = function(){
trace("Right Mouse Button Released");
}
 
But the right-click button is reserved for the context menu in Flash! You can check for a right-click, disable part of the context menu (on MX2004, you can even set up your own context menu items), but on this right-click, some context menu will always appear whether you like it or not...

Regards. Affiliate Program - Web Hosting - Web Design
 
Thanks for the help,

There must be some way around it. I know that javascript can listen for right clicks, and so can flash. So maybe when a right click is made, the javascript could do something to close the menu instantly. I know this could be done with a javascript alert, but i dont particularly want an alert to popup when the right button is pressed. And then flash could listen for the right click and get on with whatever it should be doing???
 
You could have javascript listen for the right-click but you would have to make sure the user right-clicked on the javascript area and not in the movie frame.

Once javascript caught the click you could have a function that sends parameters to the flash movie.
 
that was an idea that we had, but the tool we have created is sufficiently large for us to discount this way of doing things due to time constraints.

What works (this is really bad and i advise everyone to ignore it! unless they can take it further...) is adding this line of html code into the flash wrapper:

<PARAM name=wmode value=opaque>

And then using this code in the header:

// function to handle right-click anywhere on page
function handleclick() {
if (event.button==2)
{
blah;
}
}

// set handler function for mouse presses
document.onmousedown=handleclick;

This listens for the right click and then breaks at "blah;" because blah is undefined.
But for some reason, the right click still gets through to flash and the flash menu doesnt pop up. Obviously i get an error from IE (which is the only browser this works for... unsurprisingly) but the error is just the simple warning in the status bar.

God knows why this works, if anyone can come up with a more elegant solution, that would be great.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top