3

カーソルがフレックスアプリケーション上にあるときに、Webページでマウスホイールのスクロールを無効にすることはできますか?

私のフレックスアプリケーションは、ユーザーがマウスホイールを使用してズームインおよびズームアウトできるようにするマップです。ただし、フレックスアプリをウェブページに配置すると、スクロールホイールによってページがズームインおよびズームアウトする代わりにスクロールします...

編集:

フレックスアプリにサウンドを追加しましたが、マウスイベントが正しいことがわかります。また、JavaScriptにアラートボックスを追加して、MyApp.initialize関数が呼び出されていることを確認しましたが、マウスホイールはフレックスアプリではなくWebページをスクロールしています。これは私が使用しているコードであり、フレックスアプリケーションの上にいるときにスクロールバーをロックしていません。

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

何かが足りない!?

4

3 に答える 3

4

これは、AS3 フレックス/フラッシュに適用されます。次のコードを使用して、flex/flash swf 内でマウスホイール コントロールを許可します。マウスカーソルが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 ファイル内に、次を配置します。

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

次の URL にアクセスして、私がこれに遭遇した Web サイトにアクセスして ください。

1 週間分の作業が 5 分で解決されました...プログラミングが大好きです!

于 2010-01-09T18:16:41.517 に答える
1

答えは、externalInterface呼び出しを介してjustkevinの無効化コードを呼び出すことです。アプリケーションmouseOverでjavascript関数を呼び出して、マウススクロールホイールを無効にし、アプリケーションmouseOutで有効にします。

于 2010-01-05T18:32:37.790 に答える
0

Flex / Flash内からは実行できませんが、javascriptを使用して実行する方法はいくつかあります。

Flashアプリを使用してページにJavaScriptを配置する必要があります。すべてのブラウザで動作するとは限りません。

于 2010-01-05T15:07:30.583 に答える