flex – Chrome和Firefox中的MouseWheel

前端之家收集整理的这篇文章主要介绍了flex – Chrome和Firefox中的MouseWheel前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在advancedDataGrid中处理mouseWheel事件但没有成功.没有任何额外的代码,我的adg可以在IE中用鼠标滚动,但不能在Firefox和Chrome中滚动,为什么?为什么在这些浏览器中它的行为有所不同?

然后我尝试了这段代码,但它不起作用:

protected function adgMouseWheelHandler(event:MouseEvent):void
{
    event.delta = event.delta > 0 ? 1 : -1;
}

然后在我的adg中设置事件mouseWheel,如下所示:

<mx:AdvancedDataGrid id="myADG" width="100%" height="100%" color="0x323232" 
                     dataProvider="{_currentDatosBusqueda}" verticalScrollPolicy="auto" 
                     fontSize="11" fontFamily="Arial" fontStyle="normal" 
                     fontWeight="normal" doubleClickEnabled="true"
                     itemDoubleClick="dobleClickFilaDataGridBusqueda(event);"
                     useRollOver="true" mouseWheel="adgMouseWheelHandler(event);"
         >

有任何想法吗?

谢谢!

解决方法

修复了当wmode =“opaque”时Flex应用程序中没有MouseWheel(它实际上在IE中工作,不是Firefox或Chrome,也可能不是Safari或Opera).这也修复了Firefox和其他所有内容之间不同的MouseWheel滚动条速率.

将此JavaScript添加到您的包装器:
.

if(window.addEventListener) {
            var eventType = (navigator.userAgent.indexOf('Firefox') !=-1) ? "DOMMouseScroll" : "mousewheel";            
            window.addEventListener(eventType,handleWheel,false);
        }

        function handleWheel(event) {
            var app = document.getElementById("YOUR_APPLICATION");
            var edelta = (navigator.userAgent.indexOf('Firefox') !=-1) ? -event.detail : event.wheelDelta/40;                                   
            var o = {x: event.screenX,y: event.screenY,delta: edelta,ctrlKey: event.ctrlKey,altKey: event.altKey,shiftKey: event.shiftKey}

            app.handleWheel(o);
        }

并将此支持类放入主MXML文件(Flex4的声明):
.

package {
import flash.display.InteractiveObject;
import flash.display.Shape;
import flash.display.Stage;
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
import flash.geom.Point;

import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.events.FlexEvent;

public class MouseWheelSupport {

    //--------------------------------------
    //   Constructor 
    //--------------------------------------

    public function MouseWheelSupport() {
        FlexGlobals.topLevelApplication.addEventListener(FlexEvent.APPLICATION_COMPLETE,attachMouseWheelHandler);
    }

    //------------------------------------------------------------------------------
    //
    //   Functions  
    //
    //------------------------------------------------------------------------------

    //--------------------------------------
    //   Private 
    //--------------------------------------

    private function attachMouseWheelHandler(event : FlexEvent) : void {
        ExternalInterface.addCallback("handleWheel",handleWheel);
    }

    private function handleWheel(event : Object) : void {
        var obj : InteractiveObject = null;
        var applicationStage : Stage = FlexGlobals.topLevelApplication.stage as Stage;

        var mousePoint : Point = new Point(applicationStage.mouseX,applicationStage.mouseY);
        var objects : Array = applicationStage.getObjectsUnderPoint(mousePoint);

        for (var i : int = objects.length - 1; i >= 0; i--) {
            if (objects[i] is InteractiveObject) {
                obj = objects[i] as InteractiveObject;
                break;
            }
            else {
                if (objects[i] is Shape && (objects[i] as Shape).parent) {
                    obj = (objects[i] as Shape).parent;
                    break;
                }
            }
        }

        if (obj) {
            var mEvent : MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL,true,false,mousePoint.x,mousePoint.y,obj,event.ctrlKey,event.altKey,event.shiftKey,Number(event.delta));
            obj.dispatchEvent(mEvent);
        }
    }
}
}

JavaScript示例:

<script type="text/javascript">
        // For version detection,set to min. required Flash Player version,or 0 (or 0.0.0),for no version detection. 
        var swfVersionStr = "10.1.0";
        // To use express install,set to playerProductInstall.swf,otherwise the empty string. 
        var xiSwfUrlStr = "playerProductInstall.swf";
        var flashvars = {};
        var params = {};
        params.quality = "high";
        params.bgcolor = "#ffffff";
        params.allowscriptaccess = "sameDomain";
        params.allowfullscreen = "true";
            params.wmode = "opaque";
        var attributes = {};
        attributes.id = "YOURAPP";
        attributes.name = "YOURAPP";
        attributes.align = "middle";

            if(window.addEventListener) {
                var eventType = (navigator.userAgent.indexOf('Firefox') !=-1) ? "DOMMouseScroll" : "mousewheel";            
                window.addEventListener(eventType,false);
            }

            function handleWheel(event) {
                var app = document.getElementById("YOURAPP");
                var edelta = (navigator.userAgent.indexOf('Firefox') !=-1) ? -event.detail : event.wheelDelta/40;                                   
                var o = {x: event.screenX,shiftKey: event.shiftKey}

                app.handleWheel(o);
            }

        swfobject.embedSWF(
            "YOURAPP.swf","flashContent","100%",swfVersionStr,xiSwfUrlStr,flashvars,params,attributes);
        // JavaScript enabled so display the flashContent div in case it is not replaced with a swf object.
        swfobject.createCSS("#flashContent","display:block;text-align:left;");

    </script>
原文链接:https://www.f2er.com/flex/174365.html

猜你在找的Flex相关文章