修复了当 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,
false, Number(event.delta));
obj.dispatchEvent(mEvent);
}
}
}
}