About flex shielding default right-click menu, capture right-click events

Source: Internet
Author: User
About flex shielding default right-click menu, capture right-click events

 

JScript code

 
1 . If you are a desktop application
Monitors the mouseevent. right_click event of an event.
For example, you can right-click an event to monitor a control.
A. addeventlistener (mouseevent. right_click, func );
Other mouse events can also be monitored. For details, see http: // Livedocs.adobe.com/flex/3_cn/langref/flash/events/mouseevent.html
2 . If it is Web appliction (trouble !)
The basic idea is:

1 In Flex, you can use an external interface to register a function as an entry to receive external (HTML) Context events.
2 To intercept the right-click event in the HTML of the Flex application, call the flex external function, and cancel event broadcast to prevent the event from reaching the flex application.
3 , In the flex ApplicationProgramListen to the Mouseover event and record the object where the current mouse is located
4 When the portal function receives the right-click event sent by HTML, it simulates the generation of a right-click event (buttondown = False And send it to the current object.
5 In the mousedown processing function of the object, the left and right mouse key events are processed based on the buttondown flag.


This idea is clear and feasible. The process of right-clicking an event is as follows:

HTML right-click event ---- Flex external functions ----- Simulated right-click event ------ Corresponding processing functions

The specific implementation is as follows:

1 In the HTML where Flex is located, add
< Script >
Function Onnsrightclick (e ){
If (E. Which = 3 ){
Flextest. openrightclick ();
E. stoppropagation ();
}
Return False ;
}

Function Onierightclick (e ){
If (Event. Button > 1 ){
Flextest. openrightclick ();
Parent. frames. Location. Replace ( ' Javascript: parent. falseframe ' );
}
Return False ;
}


If (Navigator. appname = " Netscape " ){
Document. captureevents (event. mousedown );
Document. addeventlistener ( " Mousedown " , Onnsrightclick, True );
}
Else {
Document. onmousedown = Onierightclick;
}

< / SCRIPT>

2 , Modify flex mxml

< MX: Application xmlns: MX = " Http://www.adobe.com/2006/mxml " Layout = " Absolute " Initialize = " Init () " Mouseover = " Getmousetarget (Event) " >

Private VaR Mousetarget: displayobject;
Function Init ()
{
Externalinterface. addcallback ( " Openrightclick " , Openrightclick );
}


Function Getmousetarget (Event: menuevent ): Void
{
Mousetarget = Displayobject(event.tar get );
}

Function Openrightclick (): Void
{
VaR E: mouseevent = New Mouseevent (mouseevent. mouse_down, True , False , Mousetarget. mousex, mousetarget. Mousey );
Mousetarget. dispatchevent (E );
}

Function Showmouseevent (Event)
{
If (Event. buttondown = True )
Alert. Show ( " Left " );
Else
Alert. Show ( " Right " );
}


< MX: Image x = " 0 " Y = " 10 " ID = " Bbb " Name = " Bbb " Source = " Res/15.jpg " Mousedown = " Showmouseevent (Event) " Height = " 247 "/ >


After the modification is complete, perform the test with confidence. ! I have tried a lot of methods and I can't do it either. Fortunately, my colleague Zhao Hui discovered the solution. I would like to express my gratitude to him here. !

The specific method is to modify the wmode parameter and set the wmode to opaque or transparent to achieve this effect.
Ac_fl_runcontent (
" SRC " , " Playerproductinstall " ,
" Flashvars " , " Mmredirecturl = " + Mmredirecturl + ' & Mmplayertype = ' + Mmplayertype + ' & Mmdoctitle = ' + Mmdoctitle + "" ,
" Width " , " 100% " ,
" Height " , " 100% " ,
" Align " , " Middle " ,
" ID " , " Flextest " ,
" Wmode " , " Opaque " , // /// // Note:
" Quality " , " High " ,
" Bgcolor " , " #869ca7 " ,
" Name " , " Flextest " ,
" AllowScriptAccess " , " Samedomain " ,
" Type " , " Application/X-Shockwave-flash " ,
" Pluginspage " , " Http://www.adobe.com/go/getflashplayer "
);

Description of wmode in Adobe Document:
Sets the window mode property of the SWF File For Transparency, layering, and positioning In The browser. Valid values of wmode are window, opaque, and transparent.

Set to window to play the SWF In Its own rectangular window on a web page.

Set to opaque to hide everything on the page behind it.

Set to transparent so that the background of the HTML page shows through all transparent portions of the SWF file. This can slow animation performance.

To make sections of your SWF file transparent, you must set the Alpha property 0 . To make your application ' S background transparent, set the Alpha property on the <mx: Application> tag to 0.

The wmode property is not supported in all browsers and platforms.

Now you can use the right-click function flexibly! Passed the test in IE6 and ff2.0
Http://www.flex-flex.net/blog/article.asp? Id = 12



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.