合作伙伴
青啤股份公司综合信息管理软件
青岛广角汽车备件仓储管理系统
青岛中信航物流跟踪服务系统
青岛建设集团股份有限公司
青岛黄河机械有限公司
中国壁纸、软装饰行业
http://www.hollywoodbodyjewelry.com/
网站运营

网页FLASH动画禁止右键菜单的方法  

在做一个实验时遇到一个禁止flash的右键功能的问题。在网上找了很多方法,要不就完全不行,要不就浏览器不兼容。Google了一下国外的情况,终于找到了一个不错的方法。该方法用了javascript和as的结合,完美解决了问题。

  以下是javascript部分代码:

  var RightClick = {

  /**

  * Constructor

  */

  init: function () {

  this.FlashObjectID = “customRightClick”;

  this.FlashContainerID = “flashcontent”;

  this.Cache = this.FlashObjectID;

  if(window.addEventListener){

  window.addEventListener(“mousedown”, this.onGeckoMouse(), true);

  } else {

  document.getElementById(this.FlashContainerID).onmouseup = function() { document.getElementById(RightClick.FlashContainerID).releaseCapture(); }

  document.oncontextmenu = function(){ if(window.event.srcElement.id == RightClick.FlashObjectID) { return false; } else { RightClick.Cache = “nan”; }}

  document.getElementById(this.FlashContainerID).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.FlashContainerID).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();

  }

  }

  var RightClick = {

   /**

   * Constructor

   */

   init: function () {

   this.FlashObjectID = "customRightClick";

   this.FlashContainerID = "flashcontent";

   this.Cache = this.FlashObjectID;

   if(window.addEventListener){

   window.addEventListener("mousedown", this.onGeckoMouse(), true);

   } else {

   document.getElementById(this.FlashContainerID).onmouseup = function() { document.getElementById(RightClick.FlashContainerID).releaseCapture(); }

   document.oncontextmenu = function(){ if(window.event.srcElement.id == RightClick.FlashObjectID) { return false; } else { RightClick.Cache = "nan"; }}

   document.getElementById(this.FlashContainerID).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.FlashContainerID).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();

   }

  }以下是as部分代码:

  

  package {

  

  import flash.display.*;

  import flash.external.ExternalInterface;

  

  public classclass RightClick extends Sprite

  {

  

  public function RightClick()

  {

  stage.scaleMode = StageScaleMode.NO_SCALE;

  stage.align = StageAlign.TOP_LEFT;

  

  var methodName:String = “rightClick”;

  var method:Function = onRightClick;

  ExternalInterface.addCallback(methodName, method);

  }

  

  private function onRightClick():void {

  

  var mx:int = stage.mouseX;

  var my:int = stage.mouseY;

  

  if(my> 0 && my 0 && mx
  // YOUR CODE HERE

  }

  }

  }

  

  

  }

  package {

  

   import flash.display.*;

   import flash.external.ExternalInterface;

  

   public classclass RightClick extends Sprite

   {

  

   public function RightClick()

   {

   stage.scaleMode = StageScaleMode.NO_SCALE;

   stage.align = StageAlign.TOP_LEFT;

  

   var methodName:String = "rightClick";

   var method:Function = onRightClick;

   ExternalInterface.addCallback(methodName, method);

   }

  

   private function onRightClick():void {

  

   var mx:int = stage.mouseX;

   var my:int = stage.mouseY;

  

   if(my> 0 && my 0 && mx支持的浏览器有:

  

  WINDOWS VISTA

  

  Internet Explorer 7.0.6001 (16549)

  Firefox 2.0.0.6 (with mouse gestures disabled)

  Maxthon 2 (with mouse gestures disabled)

  Safari 3.0.3 (522.15.5)

  Windows XP SP2

  

  Internet Explorer 6

  Internet Explorer 7

  Maxthon 2 (with mouse gestures disabled)

  FireFox 2 (with mouse gestures disabled)

  Safari 3

  Netscape 8

  Mac OSX 10.4.10 (Intel)

  

  Firefox 2

  Safari 3.0.3

(此文章由青岛亚微网整理,本文部分资料来源网络,如有侵权请及时告诉我们!)
公司介绍    |    网站套餐     |    网站建设     |    网站优化    |    在线留言    |    联系我们
地址:青岛市南区山东路2号甲(华仁国际大厦9层E)       电话:0532-82005920            15863065784
E-Mail:zgddream@163.com QQ:491322058 MSN:xsdndream@hotmail.com
版权所有  青岛亚微德网络科技有限公司 © 2001-2009 All Rights Reserved   鲁ICP备16022819号-4
青岛亚微网专业为企业提供:青岛网站建设网站制作青岛网站设计网站推广青岛网站维护青岛网站改版青岛域名空间青岛建网站