Each time you use a network disk, such as "115 Network Disk", you can use a custom right-click menu, which is very convenient. How do you want to implement this right-click menu on the web? Not yet clear. However, right-click menus can be easily implemented in flex.
The contextmenuitem class is used to create the right-click menu in flex. The contextmenuitem class indicates the items in the context menu. Each contextmenuitem object has a title (text) displayed in the context menu ). To add a new item to the context menu, you need to add it to the customitems array of the contextmenu object. By using the attributes of the contextmenuitem class, you can enable or disable a specific menu item, or display or hide a menu item. It can be menuitemselect
Write event processing functions for events so that they can be added when the menu item is selected.
Of course, you can customize a global right-click menu or a specific right-click menu. For example, only one menu is displayed on the DataGrid, but not elsewhere. The following code is a demo for me:
<? Xmlversion = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx "minwidth =" 955 "minheight =" 600 "creationcomplete =" app_creationcompletehandler (event) "> <FX: SCRIPT> <! [CDATA [import flash. utils. clearinterval; import flash. utils. setinterval; import MX. collections. arraycollection; import MX. collections. ilist; import MX. controls. alert; import MX. controls. datagridclasses. datagriditemrenderer; import MX. core. flexglobals; import MX. events. closeevent; import MX. events. flexevent; import MX. events. listevent; [Bindable] private var contextmenucustomitems: array; [Bindable] P Rivate var CM: contextmenu; [Bindable] private var songlist: arraycollection = new arraycollection ([{showname: 'fall in love with someone else ', songer: 'yu hongming', filmname: 'chirsyu _ lslygr. flv'}, {showname: '1st year', songer: 'youhongming ', filmname: 'chirisyu _ ytywn. flv'}, {showname: 'shasha ', songer: 'youhongming', filmname: 'chirisyu _ Xs. flv'}, {showname: 'snow of June 11', songer: 'youhongming ', filmname: 'chirisyu _ wydx. flv'}, {showname: 'Woman downstairs ', songer: 'youhongming', filmname: 'chirisyu _ lxngnr. f LV '}, {showname: 'White loan', songer: 'youhongming', filmname: 'chirisyu _ bslr. flv'}]); protected function app_creationcompletehandler (Event: flexevent): void {// todoauto-generated method stub alert. oklabel = "OK"; alert. yeslabel = "yes"; alert. cancellabel = "no"; var aboutusermenu: contextmenuitem = new contextmenuitem ("About Us", true, true); aboutusermenu. addeventlistener (contextmenuevent. menu_item_select, aboutusermenuhandler); c Ontextmenucustomitems = flexglobals. toplevelapplication. contextmenu. customitems; contextmenucustomitems. push (aboutusermenu); var linkmenu: contextmenuitem = new contextmenuitem ("Contact Author", true, true); linkmenu. addeventlistener (contextmenuevent. menu_item_select, linkhandler); contextmenucustomitems. push (linkmenu);} private function aboutusermenuhandler (Event: contextmenuevent): void {alert. show ("My online storage V1.0", "prompt ");} Protected function showlist_clickhandler (Event: mouseevent): void {var OBJ: Object = showlist. selecteditem; var filename: String = OBJ ['showname'] If (filename! = "") {Createcontextmenu ("delete song", buyhandler); showlist. contextmenu = cm ;}} private function linkhandler (Event: contextmenuevent): void {alert. show ("QQ: 996475895", "prompt");} private function createcontextmenu (menuname: String, fun: function): void {CM = new contextmenu (); cm. hidebuiltinitems (); var customitemsarr: array = new array (); var custommenuitem: contextmenuitem = newcontextmenuitem (menuname, true, true); Custommenuitem. addeventlistener ("menuitemselect", fun); customitemsarr. push (custommenuitem); cm. customitems = customitemsarr;} private function buyhandler (Event: contextmenuevent): void {var showname: String = showlist. selecteditem ['showname']; alert. show (Do you really want to delete the song "'+ showname +? ', "Prompt", alert. yes | alert. cancel, this, yesorcanclehandler, null, alert. cancel);} private function yesorcanclehandler (Event: closeevent): void {If (event. detail = alert. yes) {var index: Int = showlist. selectedindex; songlist. removeitemat (INDEX); showlist. dataprovider = songlist ;}}]> </FX: SCRIPT> <FX: declarations> <! -- Place non-visualelements (e.g ., services, value objects) Here --> </FX: declarations> <mx: dataGrid id = "showlist" x = "228" Y = "97" width = "563" Height = "355" Click = "showlist_clickhandler (Event) "dataprovider =" {songlist} "fontsize =" 16 "fontweight =" bold "> <mx: columns> <mx: datagridcolumn headertext = "song name" datafield = "showname" width = "250"/> <mx: datagridcolumn headertext = "artist" datafield = "songer"/> <mx: datagridcolumn headertext = "link address" datafield = "filmname" visible = "false"/> </MX: columns> </MX: DataGrid> </S: Application>
This file creates a global right-click menu and a local right-click menu: When the cursor is not selected, the "About Us" and "Contact Author" menus are displayed, when a piece of IRD data is selected, the "delete song" right-click menu is displayed.
Of course, the right-click menu naming rules are also available, as shown below:
- You cannot add more than 15 custom menu items to the context menu.
- Each title must contain at least one visible character.
- Control characters, line breaks, and other blank characters are ignored.
- The length of a title cannot exceed 100 characters.
- Titles that are the same as any built-in menu item or other custom menu items will be ignored, regardless of whether the matching menu item is visible. The menu title is case-insensitive, punctuation marks, or blank when compared with a built-in title or an existing custom title.
- The following titles are not allowed, but can be used together with other words to form a custom title (for example, although "Paste" is not allowed ", however, you can use "paste feels good "):
Save
Zoom in
Zoom out
100%
Show all
Quality
Play
Loop
Rewind
Forward
Back
Movie not loaded
About
Print
Show redraw regions
Debugger
Undo
Cut
Copy
Paste
Delete
Select All
Open
Open in new window
Copy Link
- No matter whether it is used in combination with other words, any of the following words cannot appear in the Custom title:
Adobe
Macromedia
Flash Player
Settings
Note:If the player runs on a non-English system, the title string is compared with the English list and the corresponding localized string. For example, I added "delete" directly ". No results can be added. The original "delete" corresponds to "delete. After that, it was added to "delete Song!
However, there is a small regret. If you add this DataGrid to a container, such as panel, the right-click menu becomes invalid because only top-level containers in FLEX can create right-click menus, next I will look at the right-click menu creation in this case.
Original article, reproduced please indicate the source: http://www.dianfusoft.com/