禁用鼠标滚轮滚动时光标放在Flex应用程序? [英] disable mouse wheel scrolling while cursor over flex app?

查看:368
本文介绍了禁用鼠标滚轮滚动时光标放在Flex应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能禁用鼠标滚轮滚动在我的网页,而光标在我的Flex应用程序?

Is it possible to disable mousewheel scrolling on my webpage while the cursor is over my flex application?

我的Flex应用程序是一个映射,允许用户使用鼠标滚轮来放大和缩小;然而,当我把我的Flex应用程序到我的网页时,滚轮会导致页面,而不是滚动放大和缩小的...

My flex application is a map that allows user to zoom in and out using the mousewheel; however, when I put my flex app onto my webpage, the scrollwheel causes the page to scroll instead of zooming in and out...

编辑:

我已经加入的声音给我的Flex应用程序,它告诉我,我的鼠标事件是正确的。我还添加了一个alertbox的JavaScript,让我知道MyApp.initialize函数被调用,但鼠标滚轮依然滚动我的Flex应用程序的网页来代替。这是code,我使用并且不锁定滚动条时,我对我的Flex应用程序的顶部:

I have added sounds to my flex app and it tells me my mouse events are correct. I have also added an alertbox to the javascript so that I know the MyApp.initialize function is being called but the mousewheel is still scrolling the webpage instead of my flex app. This is the code I'm using and it isn't locking the scrollbar when I am on top of my flex application:

var bname;
var MyApp = {
   initialize : function() {  

      this.debugging = true;
      this.busyCount = 0;
      this._debug('initialize');
      bname = navigator.appName;
      //alert(bname + ‘ is browser’);
      document.getElementById('flashDiv').onload = this.start;
      if(window.addEventListener)/** DOMMouseScroll is for mozilla. */
      window.addEventListener('DOMMouseScroll', this.wheel, false);

      /** IE/Opera. */
      window.onmousewheel = document.onmousewheel = this.wheel;
      if (window.attachEvent) //IE exclusive method for binding an event
     window.attachEvent("onmousewheel", this.wheel);
      }
   , start : function() {
      window.document.network_map.focus();
      }
   , //caputer event and do nothing with it.
   wheel : function(event) {
      if(this.bname == "Netscape") {
         // alert(this.bname);
         if (event.detail)delta = 0;
         if (event.preventDefault) {
            //console.log(’prevent default exists’);
            event.preventDefault();
            event.returnValue = false;
            }
         }
      return false;
      }
   , _debug : function(msg) {
      if( this.debugging ) console.log(msg);
      }
   }; 

我得失去了一些东西!?

I have got to be missing something!?

推荐答案

这适用于AS3弯曲/闪光灯。使用下面的code,允许在弯曲/ Flash的SWF鼠标滚轮控制。它会滚动浏览器时,鼠标光标的Flex / Flash的SWF之外。

This applies to AS3 flex/flash. Use the following code to allow mousewheel controls within flex/flash swf. it will scroll browser when mouse cursor is outside of flex/flash swf.

package com.custom {

import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.external.ExternalInterface;

/**
 * MouseWheelTrap - Simultaneous browser/Flash mousewheel scroll issue work-around
 * @version 0.1
 * @author Liam O'Donnell
 * @usage Simply call the static method MouseWheelTrap.setup(stage)
 * @see http://www.spikything.com/blog/?s=mousewheeltrap for updates
 * This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
 * (c) 2009 spikything.com
 */

public class MouseWheelTrap {

    static private var _mouseWheelTrapped :Boolean;

    public static function setup(mainStage:Stage):void {

        mainStage.addEventListener(MouseEvent.ROLL_OVER, function():void{ 
            allowBrowserScroll(false); 
            }
        );

        //i added 'mx.core.FlexGlobals.topLevelApplication.'making it work better for flex. use 'stage' for flash   
        mainStage.addEventListener(MouseEvent.ROLL_OUT, function():void{ 
            allowBrowserScroll(true); 
            }
        );
    }

    private static function allowBrowserScroll(allow:Boolean):void
    {
        createMouseWheelTrap();
        if (ExternalInterface.available){
            ExternalInterface.call("allowBrowserScroll", allow);
        }
    }
    private static function createMouseWheelTrap():void
    {
        if (_mouseWheelTrapped) {return;} _mouseWheelTrapped = true; 
        if (ExternalInterface.available){
            ExternalInterface.call("eval", "var browserScrolling;function allowBrowserScroll(value){browserScrolling=value;}function handle(delta){if(!browserScrolling){return false;}return true;}function wheel(event){var delta=0;if(!event){event=window.event;}if(event.wheelDelta){delta=event.wheelDelta/120;}else if(event.detail){delta=-event.detail/3;}if(delta){handle(delta);}if(!browserScrolling){if(event.preventDefault){event.preventDefault();}event.returnValue=false;}}if(window.addEventListener){window.addEventListener('DOMMouseScroll',wheel,false);}window.onmousewheel=document.onmousewheel=wheel;allowBrowserScroll(true);");
        }
    }
  }
}

在你的主Flash文档第1帧或者其它任何或在您的主Flex MXML文件,将以下内容:

Within your main flash document "frame 1 or where ever" or in your main flex mxml file, place the following:

import com.custom.MouseWheelTrap;
MouseWheelTrap.setup(stage);

您可以访问,我偶然发现了这个通过访问以下网址的网站: <一href="http://www.spikything.com/blog/index.php/2009/11/27/stop-simultaneous-flash-browser-scrolling/" rel="nofollow">http://www.spikything.com/blog/index.php/2009/11/27/stop-simultaneous-flash-browser-scrolling/

you may visit the website where I stumbled upon this by visiting the following URL: http://www.spikything.com/blog/index.php/2009/11/27/stop-simultaneous-flash-browser-scrolling/

一个星期的价值终于解决了在5分钟内的工作......得爱编程!

A weeks worth of work finally solved in 5 minutes...gotta love programming!

这篇关于禁用鼠标滚轮滚动时光标放在Flex应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆