[Original article http://blog.csdn.net/cjy37/article/details/3954516]
Step 1:To success!
Step 2:Open: <mainProgramName> .template.html file, changed:
<! -- Ac_fl_runcontent ("src", "$ {SWF}", "ID", "$ {application}", "name", "$ {application}", "width ", "$ {width}", "height", "$ {height}", "align", "Middle", "menu", "false", "wmode ", "Opaque", // note: the Key to right-click blocking is "quality", "high", "bgcolor", "$ {bgcolor}", "allowScriptAccess ", "Always", "allownetworking", "all", "allowfullscreen", "true", // whether the full-screen parameter "type ", "Application/X-Shockwave-flash", "pluginspage", "http://www.adobe.com/go/getflashplayer"); // -->
Step 3:Introduce the following in the main program file.:
Import com. siloon. plugin. rightclick. rightclickmanager;
Add the followingCode:
[Event (name = "rightclick", type = "FLA Sh. events. contextmenuevent ")] public class index {protected var rightclickregisted: Boolean = false; Public Function Index () {super (); If (! Rightclickregisted) {rightclickmanager. regist (); rightclickregisted = true;} Try {name = nameutil. createuniquename (this);} catch (E: Error) {} return;} public override function tostring (): String {return nameutil. displayobjecttostring (this );}
Step 4:In the initialization code of the control to be right-clicked, add:
Navtabtree. addeventlistener (rightclickmanager. right_click, rightclickhandler );
Add the following functions:
/*** Right-click the processing function of the menu event on the control * @ Param event right-click the event **/protected function rightclickhandler (Event: contextmenuevent): void {onrightclicked (event ); removemenu (); menu = new menu (); menu = menu. createmenu (this, createmenuitems (), false); menu. labelfield = "label" menu. variablerowheight = true; // menu. addeventlistener (menuevent. item_click, menuitemclickhandler); var point: Point = new point (mousex, Mousey); point = Loc Altoglobal (point); menu. show (point. x, point. y);}/*** If menu is displayed, release the resource first **/private function removemenu (): void {If (menu! = NULL) {menu. hide (); // menu. removeeventlistener (menuevent. item_click, menuitemclickhandler); menu = NULL ;}/ *** create a right-click menu option * @ return returns an array of options **/private function createmenuitems (): array {var menuitems: array = new array (); var menuitem: object; menuitem = new object; menuitem. label = 'empty canvas '; menuitem. action = 'clearall'; menuitems. push (menuitem); menuitem = new object; menuitem. label = 'select backgrounds '; menuitem. action = 'Selectbackimage'; menuitems. push (menuitem); Return menuitems;}/*** when you right-click the item in the tree, automatically select the current item * @ Param e custom right-click menu event */private function onrightclicked (E: contextmenuevent): void {var rightclickitemrender: ilistitemrenderer; var rightclickindex: int; if (E. mousetarget is ilistitemrenderer) {rightclickitemrender = ilistitemrenderer (E. mousetarget);} else if (E. mousetarget. parent is ilistitemrenderer) {Rightclickitemrender = ilistitemrenderer (E. mousetarget. Parent);} If (rightclickitemrender! = NULL) {rightclickindex = navtabtree. itemrenderertoindex (rightclickitemrender); If (navtabtree. selectedindex! = Rightclickindex) {navtabtree. selectedindex = rightclickindex ;}}}
Step 5:
Modify
Static private var rightclicktarget:*;
Modify the two functions of the file:
Static Private Function mouseoverhandler ( Event : Mouseevent ): Void {Rightclicktarget = Interactiveobject ( Event . Target ); Return ;} Static Private Function dispatchrightclickevent (): Void { VaR Event : Contextmenuevent; If (Rightclicktarget! = Null ){ Event = New Contextmenuevent (right_click,True , False , Rightclicktarget As Interactiveobject, rightclicktarget As Interactiveobject); rightclicktarget. dispatchevent ( Event );} // End if Return ;}
Now, the function is complete. I changed the rightclickmanager event from mouseevent to contextmenuevent to automatically select the current row when right-clicking on the list control DataGrid/tree/list, the event in the contextmenuevent event is used. the ilistitemrenderer interface of mousetarget and list control!
This function also has side effects. If the context menu of the system is invalid, the right-click copy and paste of the text will become invalid. You must be careful when using textinput in a large number of ways ~!