zoukankan      html  css  js  c++  java
  • flex中定制右键菜单

    一、将flex的所有右键屏蔽,并响应右键
    第一步:
    在swf 所在html页加如下内容:
    <script>
    function onNsRightClick(e){
    if(e.which == 3){
      ownerarea.openRightClick();
      e.stopPropagation();
    }
    return false;
    }

    function onIeRightClick(e){
    if(event.button > 1){
      ownerarea.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>

    第二步:
    swf所在html文件中AC_FL_RunContent中增加
    "wmode", "opaque", 

    第三步:flex中
    <mx:Application creationComplete="init();" mouseOver="getMouseTarget(event)">
    <mx:Script>
    private var mouseTarget:DisplayObject;

    private function init(): void{
    ExternalInterface.addCallback("openRightClick", openRightClick);
    }

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

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

    function showMouseEvent(event){
    //通过event.buttonDown为true和flash可以得到左键点击或右键点击
    // 但加入菜单没有效果,需要再研究
    var menu: Menu = new Menu();
    menu = Menu.createMenu(null, buildMenu);
    menu.labelField = "@label";
    menu.show(10,10);
    }
    </mx:Script>
    <mx:XML format="e4x" id="buildMenu">
    <root>
    <menuitem label="新建">
    </menuitem>
    </root>
    </mx:XML>
    <mx:Image x="62" source="../images/info_btn.gif" id="baseDataBtn" bottom="0" mouseDown="showMouseEvent(event)"/>
    </mx:Application>
  • 相关阅读:
    ASP.NET MVC3 系列教程 部署你的WEB应用到IIS 6.0
    ASP.NET MVC3 系列教程 控制器 & 视图
    Windows 8 如何安装到Virtual Box虚拟机上(x86)
    工具脚本(网络编码)
    c库的rand/random随机数产生函数性能差?
    shell脚本模版
    linux的IO调度算法和回写机制
    thrift安装脚本
    通用高效的c++内存池(特定类型)
    [转] NoSQL生态系统
  • 原文地址:https://www.cnblogs.com/nianshi/p/1774378.html
Copyright © 2011-2022 走看看