国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

5.12.為L(zhǎng)ist創(chuàng)建右鍵菜單

2024-04-27 13:51:57
字體:
供稿:網(wǎng)友
5.12.1.問題
當(dāng)用戶在特定的條目上右鍵單擊或按住Control 鍵并單擊(在Macintosh 中譯者注)時(shí)創(chuàng)建一個(gè)定制上下文菜單項(xiàng)來顯示
5.12.2.解決方法
創(chuàng)建ContextMenu 和ContextMenuItem 對(duì)象并分派它們到渲染器,它們將像itemRenderer一樣被分派到列表.
5.12.3.討論
上下文菜單項(xiàng)是用戶在flex 應(yīng)用程序上右鍵單擊或按住Control 鍵并單擊以后出現(xiàn)的,默認(rèn)情況下,菜單顯示像flashplayer9 屏幕信息鏈接一樣的Loop, Play, Print, Quality, Rewind,Save, 和Zoom 控制。但是你可以創(chuàng)建一個(gè)新的ContextMenu 對(duì)象從而很容易地定制這個(gè)菜單.簡(jiǎn)單地調(diào)用ContextMenu 的構(gòu)造函數(shù)并設(shè)置contextMenu 屬性的對(duì)象為創(chuàng)建好的顯示對(duì)象,如下所示:
+展開
-ActionScript
var menu:ContentMenu = new ContextMenu();
this.contextMenu = menu;

這段代碼需要在DisplayObject 上運(yùn)行,也就是說,任何顯示對(duì)象。用戶在DisplayObject或組件上右鍵單擊或按住Control 鍵并單擊時(shí)被創(chuàng)建的定制上下文菜單項(xiàng)才會(huì)顯示設(shè)置好的contentMenu 屬性。

使用由ContextMenu 定義的customItems 數(shù)組,為上下文菜單項(xiàng)添加新的項(xiàng)。實(shí)例化新的ContextMenuItem 對(duì)象并使用push 方法將它們添加到數(shù)組。

ContextMenuItem 的構(gòu)告函數(shù)具有如下信息。
+展開
-ActionScript
ContextMenuItem(caption:String, separatorBefore:Boolean = false, enabled:Boolean = true,visible:Boolean = true)

Caption 屬性決定了菜單項(xiàng)的標(biāo)題如,查詢職工信息,separatorBefore 屬性決定了是否需要一條細(xì)線出現(xiàn)在菜單中的ContextMenuItem 上以區(qū)分菜單項(xiàng)。最終情況下,visible 和enabled 屬性決定各個(gè)條目是否是用戶可見和可選的.

當(dāng)用戶選擇該條目時(shí)ContextMenuItem 發(fā)出一個(gè)SELECT 類型的ContextMenuEvent 事件。

下面例子為L(zhǎng)ist 控件創(chuàng)建了一個(gè)渲染器并基于List 傳入的數(shù)據(jù)類型來創(chuàng)建上下文菜單項(xiàng)。
+展開
-XML
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxmlwidth="150height="80paddingLeft="10">
<mx:Script>
<![CDATA[
import flash.display.*;
override public function set data(value:Object):void {
if (value is Name) {
text1.text = value.firstName;
text2.text = value.lastName;
var personMenu:ContextMenu = new ContextMenu();
var lookupRecord:ContextMenuItem = new ContextMenuItem("Look Up Record" );
var lookupPicture:ContextMenuItem = new ContextMenuItem("Look Up Picture" );
personMenu.customItems.push(lookupRecord);
personMenu.customItems.push(lookupPicture);
this.contextMenu = personMenu;
}
else if (value is Office) {
text1.text = value.officeAddress;
text2.text = value.officeName;
var officeMenu:ContextMenu = newContextMenu();
var lookupMap:ContextMenuItem =new ContextMenuItem("Look Up Map");
lookupMap.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,showMap);
var lookupEmployees:ContextMenuItem =new ContextMenuItem("Look Up Employees");
lookupEmployees.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, showEmployees);
officeMenu.customItems.push(lookupEmployees);
officeMenu.customItems.push(lookupMap);
this.contextMenu = officeMenu;
}
}
private function showMap(event:ContextMenuEvent):void {
//do something with the map
}
private function showEmployees(event:ContextMenuEvent):void {
//do something to look up all the employees
}

]]>
</mx:Script>
<mx:Text id="text1"/>
<mx:Text id="text2"/>
</mx:VBox>
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 德阳市| 阿拉善左旗| 登封市| 金阳县| 丹江口市| 亚东县| 通化市| 揭阳市| 平远县| 迭部县| 定兴县| 南安市| 邯郸县| 松溪县| 高阳县| 清水河县| 奉新县| 新巴尔虎左旗| 伊川县| 名山县| 内丘县| 阿城市| 河东区| 通江县| 特克斯县| 博兴县| 焦作市| 桓台县| 郯城县| 许昌县| 沙洋县| 荣成市| 湖口县| 南皮县| 宁陕县| 邢台县| 孟州市| 甘谷县| 新河县| 辉南县| 龙海市|