首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

关于Flex屏蔽默认右键菜单,捕获右键事件解决方法

2013-01-26 
关于Flex屏蔽默认右键菜单,捕获右键事件在Flex实现 屏蔽默认右键菜单,捕获右键事件,网上千篇一律,Google开

关于Flex屏蔽默认右键菜单,捕获右键事件
在Flex实现 屏蔽默认右键菜单,捕获右键事件,网上千篇一律,Google开源中有一个开源项目,实现了这个功能,但是都有有几个弊端:中文输入法支持不好,这个很致命,而且在全屏模式下无效;

网上流传的解决办法看原理是讲的过去的,在IE6上也是可以的,但是发现在IE8下就无效了;可以截获右键事件,但是屏蔽不了默认的flash右键菜单!

自己想通过修改修改tml模板和AC_OETags.js,在flash控件上添加DIV来截获,发现控件的优先级比DIV要高,只有iframe能盖住控件,这样就不可行了,iframe自身不能截获事件,智能是iframe内的页面;


不知各位高手是否有好的解决办法,请教一下!


附上网上流传的解决办法


1.如果你是Desktop Application
监听事件的MouseEvent.RIGHT_CLICK事件 
比如对某个控件a进行监控右键点击事件 
a.addEventListener(MouseEvent.RIGHT_CLICK,func); 
鼠标的其他事件也可以监听,具体见http://livedocs.adobe.com/flex/3_cn/langref/flash/events/MouseEvent.html 
2.如果是Web Appliction(麻烦了!)
其基本思路为:

1,在FLEX中利用外部接口注册一个函数, 作为接收外部(HTML)右键事件的入口
2,在FLEX应用所在的HTML中拦截鼠标右键事件,调用FLEX外部函数,并取消事件的广播,以阻止事件到达FLEX应用.
3,在FLEX应用程序上监听mouseOver事件,并记录当前鼠标所在对象
4,当入口函数接收到HTML发送的右键事件后,模拟生成一个鼠标右键事件(buttonDown = false), 并发送到当前对象
5,在对象的mouseDown处理函数中,根据buttonDown的标志,分别处理鼠标左右键事件


这个思路比较清晰可行, 鼠标右键事件的流程为:

HTML鼠标右键事件----FLEX外部函数-----模拟的鼠标右键事件------相应的处理函数

具体的实现为:

1, 在FLEX所在的HTML增加
<script>
function onNsRightClick(e){
if(e.which == 3){
   FlexTest.openRightClick();
   e.stopPropagation(); 
}
return false;
}

function onIeRightClick(e){
if(event.button > 1){
   FlexTest.openRightClick();
   parent.frames.location.replace('javascript: parent.falseframe');
}
return false;
}


if(navigator.appName == "Netscape"){
document.captureEvents(Event.MOUSEDOWN); 
document.addEventListener("mousedown", onNsRightClick, true); 
}
else{
document.onmousedown=onIeRightClick; 
}

</script>

2, 修改FLEX的MXML

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()" mouseOver="getMouseTarget(event)" >

private var mouseTarget:DisplayObject;
function init()
{
ExternalInterface.addCallback("openRightClick", openRightClick);
}


function getMouseTarget(event:MenuEvent):void
{
mouseTarget = DisplayObject(event.target);
}

function openRightClick():void
{
var e:MouseEvent = new MouseEvent(MouseEvent.MOUSE_DOWN, true, false, mouseTarget.mouseX, mouseTarget.mouseY);
mouseTarget.dispatchEvent(e);
}

function showMouseEvent(event)
{
if(event.buttonDown == true)
   Alert.show("Left");
else
   Alert.show("Right");
}


<mx:Image x="0" y="10" id="bbb" name="bbb" source="res/15.jpg" mouseDown="showMouseEvent(event)" height="247"/>


在修改完后,满怀信心的进行测试,结果右键菜单还能够出现!试了很多办法也不行,幸亏我的同事赵辉发现了解决方法,在这里向他表示感谢!

具体的方法就是修改wmode参数, 将wmode设置为opaque或transparent都可以达到这个效果
AC_FL_RunContent(
   "src", "playerProductInstall",
   "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
   "width", "100%",
   "height", "100%",
   "align", "middle",
   "id", "FlexTest",
   "wmode", "opaque", //////////////////////注意:这里是关键
   "quality", "high",
   "bgcolor", "#869ca7",
   "name", "FlexTest",
   "allowScriptAccess","sameDomain",


   "type", "application/x-shockwave-flash",
   "pluginspage", "http://www.adobe.com/go/getflashplayer"
);

ADOBE文档中对wmode的解释: 
Sets the Window Mode property of the SWF file for transparency, layering, and positioning in the browser. Valid values of wmode are window, opaque, and transparent.

Set to window to play the SWF in its own rectangular window on a web page.

Set to opaque to hide everything on the page behind it.

Set to transparent so that the background of the HTML page shows through all transparent portions of the SWF file. This can slow animation performance.

To make sections of your SWF file transparent, you must set the alpha property to 0. To make your application's background transparent, set the alpha property on the <mx:Application> tag to 0.

The wmode property is not supported in all browsers and platforms.

现在就可以灵活的使用鼠标右键功能了!在IE6和FF2.0中测试通过
http://www.flex-flex.net/blog/article.asp?id=12 



[解决办法]
真的没有,至少我找不到了
[解决办法]
这个问题确实不好解决,暂时没思路!关注中~~~~
[解决办法]
我flex不在行,但最近也要实现右键菜单:右击打开一个菜单,当点击菜单中的某项,实现相应功能。那位老兄有解决之道???支援一下
[解决办法]
这个问题解决不了的
[解决办法]
引用:
顶自己的帖可有分领啊

。。。。。。。。。。。。。。
[解决办法]
关注。。。。
[解决办法]
全屏的时候就会屏蔽了一些事件,所以会出现问题,这个弊端在这样的情况下无法解决
[解决办法]
我也遇到这问题,找不到办法解决。

热点排行