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

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

5.12.為List創(chuàng)建右鍵菜單

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

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

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

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

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

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

下面例子為List 控件創(chuàng)建了一個渲染器并基于List 傳入的數(shù)據(jù)類型來創(chuà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ā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 什邡市| 米林县| 文昌市| 贡嘎县| 弥渡县| 常山县| 绥中县| 石林| 临沂市| 泌阳县| 石楼县| 东乌珠穆沁旗| 桂平市| 丰原市| 万州区| 加查县| 曲松县| 古交市| 大同县| 卢氏县| 崇文区| 双牌县| 阿拉尔市| 大新县| 酉阳| 同江市| 诏安县| 宜宾市| 剑河县| 玉屏| 遂宁市| 浦北县| 缙云县| 军事| 开远市| 周宁县| 栖霞市| 遂平县| 衡阳县| 门源| 肥乡县|