Flex 사용자 정의 오른쪽 단추 메뉴 구현

1.오른쪽 키 메뉴 등록 클래스 사용자 정의:항목 에 등록 클래스 RightClickManager 가 추가 되 었 습 니 다.코드 는 다음 과 같 습 니 다
 
package com.siloon.plugin.rightClick
{
import flash.display.DisplayObject;
import flash.display.InteractiveObject;
import flash.events.ContextMenuEvent;
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
import mx.core.Application;
public class RightClickManager
{
static private var rightClickTarget:DisplayObject;
static public const RIGHT_CLICK:String = "rightClick";
static private const javascript:XML =
<script>
<![CDATA[
/**
*
* Copyright 2007
*
* Paulius Uza
* http://www.uza.lt
*
* Dan Florio
* http://www.polygeek.com
*
* Project website:
* http://code.google.com/p/custom-context-menu/
*
* --
* RightClick for Flash Player.
* Version 0.6.2
*
*/
function(flashObjectId)
{
var RightClick = {
/**
* Constructor
*/
init: function (flashObjectId) {
this.FlashObjectID = flashObjectId;
this.Cache = this.FlashObjectID;
if(window.addEventListener){
window.addEventListener("mousedown", this.onGeckoMouse(), true);
} else {
document.getElementById(this.FlashObjectID).parentNode.onmouseup = function() { document.getElementById(RightClick.FlashObjectID).parentNode.releaseCapture(); }
document.oncontextmenu = function(){ if(window.event.srcElement.id == RightClick.FlashObjectID) { return false; } else { RightClick.Cache = "nan"; }}
document.getElementById(this.FlashObjectID).parentNode.onmousedown = RightClick.onIEMouse;
}
},
/**
* GECKO / WEBKIT event overkill
* @param {Object} eventObject
*/
killEvents: function(eventObject) {
if(eventObject) {
if (eventObject.stopPropagation) eventObject.stopPropagation();
if (eventObject.preventDefault) eventObject.preventDefault();
if (eventObject.preventCapture) eventObject.preventCapture();
if (eventObject.preventBubble) eventObject.preventBubble();
}
},
/**
* GECKO / WEBKIT call right click
* @param {Object} ev
*/
onGeckoMouse: function(ev) {
return function(ev) {
if (ev.button != 0) {
RightClick.killEvents(ev);
if(ev.target.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
RightClick.call();
}
RightClick.Cache = ev.target.id;
}
}
},
/**
* IE call right click
* @param {Object} ev
*/
onIEMouse: function() {
if (event.button > 1) {
if(window.event.srcElement.id == RightClick.FlashObjectID && RightClick.Cache == RightClick.FlashObjectID) {
RightClick.call();
}
document.getElementById(RightClick.FlashObjectID).parentNode.setCapture();
if(window.event.srcElement.id)
RightClick.Cache = window.event.srcElement.id;
}
},
/**
* Main call to Flash External Interface
*/
call: function() {
document.getElementById(this.FlashObjectID).rightClick();
}
}
RightClick.init(flashObjectId);
}
]]>
</script>;
public function RightClickManager()
{
return;
}
static public function regist() : Boolean
{
if (ExternalInterface.available)
{
ExternalInterface.call(javascript, ExternalInterface.objectID);
ExternalInterface.addCallback("rightClick", dispatchRightClickEvent);
Application.application.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
}// end if
return true;
}
static private function mouseOverHandler(event:MouseEvent) : void
{
//rightClickTarget = DisplayObject(event.target);
rightClickTarget = InteractiveObject(event.target);
return;
}
static private function dispatchRightClickEvent() : void
{
var event:MouseEvent;
if (rightClickTarget != null)
{
event = new MouseEvent(RIGHT_CLICK, true, false, rightClickTarget.mouseX, rightClickTarget.mouseY);
//event = new ContextMenuEvent(RIGHT_CLICK, true, false, rightClickTarget as InteractiveObject, rightClickTarget as InteractiveObject);
rightClickTarget.dispatchEvent(event);
}// end if
return;
}
}
}
2.자신의 Flex 프로젝트 의 html-template 폴 더 에 있 는 index.template.html 파일(오른쪽 클릭-open With-Text Editor)을 열 고 var params={};문장의 아래 에 다음 문장 을 추가 합 니 다:params.wmode="opaque";/시스템 오른쪽 키 메뉴 를 차단 하 는 관건

좋은 웹페이지 즐겨찾기