Flex自定义右键菜单具体实现(flex实现左边固定右边自适应)万万没想到

随心笔谈2年前发布 编辑
166 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

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=

function(flashObjectId)

{

var RightClick={

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;

}

},

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();

}

},

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;

}

}

},

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;

}

},

call: function() {

document.getElementById(this.FlashObjectID).rightClick();

}

}

RightClick.init(flashObjectId);

}

]]>

;

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;

}

}

}

© 版权声明

相关文章