コンテキストメニューについて:HTML(AIR)Adobe AIR 1.0 およびそれ以降 HTMLLoader オブジェクトを使用して表示される HTML コンテンツでは、contextmenu イベントを使用してコンテキストメニューを表示できます。デフォルトでは、ユーザーが選択したテキストで(テキストを右クリックするか Command キーを押しながらクリックして)コンテキストメニューを呼び出すと、自動的にコンテキストメニューが表示されます。デフォルトのメニューが開かないようにするには、contextmenu イベントをリッスンし、そのイベントオブジェクトの preventDefault() メソッドを呼び出します。 function showContextMenu(event){ event.preventDefault(); } その後、DHTML の手法を使用するか AIR のネイティブコンテキストメニューを表示して、カスタムコンテキストメニューを表示できます。次の例では、HTML の contextmenu イベントに応答してメニューの display() メソッドを呼び出すことにより、ネイティブコンテキストメニューを表示します。 <html> <head> <script src="AIRAliases.js" language="JavaScript" type="text/javascript"></script> <script language="javascript" type="text/javascript"> function showContextMenu(event){ event.preventDefault(); contextMenu.display(window.nativeWindow.stage, event.clientX, event.clientY); } function createContextMenu(){ var menu = new air.NativeMenu(); var command = menu.addItem(new air.NativeMenuItem("Custom command")); command.addEventListener(air.Event.SELECT, onCommand); return menu; } function onCommand(){ air.trace("Context command invoked."); } var contextMenu = createContextMenu(); </script> </head> <body> <p oncontextmenu="showContextMenu(event)" style="-khtml-user-select:auto;">Custom context menu.</p> </body> </html> |
![]() |