我創造了幾十標籤超過一個組,我加了右鍵菜單用於每一個標籤,然後附加一個事件監聽菜單,那麼我怎樣才能得到確切的標籤,我右擊的通過菜單項選擇監聽器(ContextMenuEvent.MENU_ITEM_SELECT)?非常感謝右鍵單擊標籤和彈出菜單,我怎樣才能從菜單項選擇監聽器的按鈕?
0
A
回答
0
一個解決方案是創建一個包含標籤和菜單外觀部件的自定義組件。通過這種方式,您還可以以任何您想要的方式對組件進行蒙皮處理,並以非常簡單的方式訪問標籤以及菜單。
爲了解決您的問題,我們假設皮膚部件被命名爲'標籤'和'菜單'。在調度ContextMenuEvent時,可以通過訪問菜單點擊處理程序中的event.target屬性來訪問點擊菜單。現在,它的父項將通過其父項屬性可用,這是您如何訪問標籤組件或皮膚部件的方式。因此,這將是這樣的:
event.target.parent.label
其中:
event.target - 菜單組件
event.target。父母 - 您的組件圍繞標籤和菜單環繞
event.target.parent.label - 您想要訪問的組件
總結一下,創建一個自定義組件,它包裝一個標籤和一個菜單,並將其作爲其皮膚部件。這樣,通過識別兩個部分中的任何一個(例如在事件處理程序中),您可以通過父級屬性輕鬆確定其他相應的組件。
您可能需要將event.target值轉換成菜單類,而event.target.parent屬性,您的自定義組件類,則標籤將可用。
0
如果您正在使用標籤作爲組分比你可以訪問它:
event.contextMenuOwner.text
或
如果您使用的按鍵比你可以訪問它:
event.contextMenuOwner.label
希望這可能有所幫助。
0
當我點擊任何菜單項時,它的mouseTarget屬性將包含iformation緊靠它的父項。
// Handler when customized menu items are selected.
private function menuItemHandler(event:ContextMenuEvent):void {
var obj:InteractiveObject = event.mouseTarget;
if(obj is Label)
Alert.show(Label(obj).id);
}
檢查是否有幫助。
小應用程序。
<?xml version="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="init()">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
[Bindable]
private var cm:ContextMenu;
private var cmi:ContextMenuItem;
private var item1:ContextMenuItem;
private var item2:ContextMenuItem;
private var item3:ContextMenuItem;
private var item4:ContextMenuItem;
private var item5:ContextMenuItem;
private function init():void
{
cmi = new ContextMenuItem("Some Context Item");
cmi.enabled = false;
item1 = new ContextMenuItem("Customized item", true);
item2 = new ContextMenuItem("Enable/Disable customized menu entry", true);
item3 = new ContextMenuItem("Visible/Invisible customized menu entry");
item4 = new ContextMenuItem("Copy\u00A0");
item5 = new ContextMenuItem("More Flex tutorials", true);
// Manage clicks on your customized items
item1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemHandler);
item2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemHandler);
item3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemHandler);
item4.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemHandler);
item5.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemHandler);
cm = new ContextMenu();
cm.hideBuiltInItems();
cm.customItems = [cmi, item1, item2, item3, item4, item5];
cm.addEventListener(ContextMenuEvent.MENU_SELECT, onMnuSelect);
}
private function onMnuSelect(event:ContextMenuEvent):void
{
/* var obj:InteractiveObject = event.mouseTarget;
if(obj is Label)
Alert.show(Label(obj).id); */
}
// Handler when customized menu items are selected.
private function menuItemHandler(event:ContextMenuEvent):void {
var obj:InteractiveObject = event.mouseTarget;
if(obj is Label)
Alert.show(Label(obj).id);
}
]]>
</fx:Script>
<s:VGroup>
<s:Label id="label1" text="label1" contextMenu="{cm}"/>
<s:Label id="label2" text="label2" contextMenu="{cm}"/>
<s:Label id="label3" text="label3" contextMenu="{cm}"/>
<s:Label id="label4" text="label4" contextMenu="{cm}"/>
</s:VGroup>
</s:Application>
相關問題
- 1. 右鍵單擊從菜單中選擇的菜單
- 2. 右鍵單擊菜單選項
- 3. 彈出按鈕菜單項
- 4. 我怎樣才能保持CSS樣式選擇菜單項點擊
- 5. 在WinRT中顯示彈出式右鍵單擊樣式菜單
- 6. 使用vue-router,我怎樣才能讓菜單選擇樣式?
- 7. 從量角器中的右鍵單擊菜單中選擇翻譯選項
- 8. eclipse監聽器主菜單欄選擇
- 9. SWT瀏覽器控件右鍵單擊彈出菜單調用按鈕的功能單擊
- 10. NSStatusItem右鍵單擊菜單
- 11. NSEvent單擊右鍵菜單
- 12. 右鍵單擊datagrid單元格以彈出複製菜單(ContextMenu)
- 13. Flex菜單控制 - 單擊一個按鈕並顯示一個菜單。我怎樣才能再次點擊該按鈕並隱藏該菜單?
- 14. 彈出按鈕右鍵單擊+ WPF
- 15. 我怎樣才能在右側使用yii2的邊欄菜單
- 16. CSS和HTML水平彈出菜單 - 右側彈出菜單
- 17. 我怎樣才能只選擇一個單選按鈕?
- 18. 選擇Firefox瀏覽器的「後退」按鈕,右鍵單擊並從右鍵菜單中選擇Selenium Web Driver菜單 - Java
- 19. 菜單左,右鍵菜單
- 20. 處理中的右鍵單擊彈出菜單
- 21. 菜單條中單擊項偵聽器
- 22. 右擊事件後的菜單彈出
- 23. 彈出窗口中的右鍵菜單
- 24. 按下菜單按鈕時不會出現android選項菜單
- 25. 單擊按鈕上的菜單項
- 26. 我怎樣才能居中我的菜單項?
- 27. 右鍵單擊和菜單欄菜單如何工作?
- 28. 菜單上的java動作監聽器,而不是菜單項
- 29. 在按鈕上的Extjs上下文菜單(右鍵單擊)
- 30. 如何對齊菜單項彈出的菜單的右下角