好的,首先我遇到2个问题,默认wmode为“window”。我的网页导航菜单将在我的flex / flash应用程序下。另一个问题是在Flash应用程序中滚动整个页面会滚动。
我将wmode更改为“opaque”,这解决了导航菜单的问题,现在它们显示在Flash应用上方。多数民众赞成好,但现在我在Flash应用程序中根本没有滚动。
我意识到这是一个很大的问题,但我似乎无法找到解决这两个问题(实际上是2.5个问题)的任何解决方案。
我想A)导航链接显示在Flash应用程序上方,因此它们不会被隐藏; B)允许在Flash应用程序内滚动;和C)如果鼠标悬停在Flash应用程序上,则阻止滚动网页。
如果你们有任何想法会很棒。 :)提前谢谢。
答案 0 :(得分:5)
我写的时候的意思是:
wmode = transparent& wmode = opaque与鼠标滚轮的行为相同。
在大多数浏览器中,两种模式都不会捕获闪存中的MOUSE_WHEEL
事件(我相信IE是唯一能够正确捕获MOUSE_WHEEL
事件的浏览器。)
解决方案是通过JavaScript监听MOUSE_WHEEL
事件:
//ie handles wmode=transparent correctly
//every other browser uses addEventListener
if ( !document.attachEvent )
{
//console.log('attached');
window.addEventListener('DOMMouseScroll', scrollListener, false);
window.addEventListener('mousewheel', scrollListener, false);
}
scrollListener( e )
{
var delta
if ( e.wheelDelta )
{
delta = e.wheelDelta / 40;
}
else if ( e.detail )
{
delta = -e.detail;
}
//do stuff with delta
}
然后,您需要使用ExternalInterface.addCallback
为JS设置回调,以警告Flash发生了MOUSE_WHEEL
事件。
wmode=transparent
& wmode=opaque
也存在其他鼠标事件的问题。
答案 1 :(得分:1)
当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);
}
}
}
}
答案 2 :(得分:1)
我真的能够在zzzzBov的良好链接之后解决所有三个问题。这让我可以将鼠标滚动到Flash应用程序,只有当鼠标悬停在Flash应用程序上时才会这样做。它还允许我的Flash应用程序保持“不透明”模式,以便它不高于页面上的其他HTML元素。
找到了一个例子here
<强>的Javascript 强>
$(document).ready(function () {
$('#MapSWFDiv').bind('mousewheel', function (event) {
HandleMouseWheel(event);
return false;
});
//Firefox
$('#MapSWFDiv').bind('DOMMouseScroll', function (event) {
HandleMouseWheel(event);
return false;
});
});
function HandleMouseWheel(event) {
var app = GetMapSWF();
if (app) {
var delta = event.wheelDelta ? event.wheelDelta : event.detail;
var o = { x: event.clientX, y: event.clientY,
delta: delta,
ctrlKey: event.ctrlKey, altKey: event.altKey,
shiftKey: event.shiftKey
}
app.HandleMouseWheel(o);
}
}
<强>的Flex 强>
protected function appComplete():void {
ExternalInterface.addCallback("HandleMouseWheel", HandleMouseWheel);
}
//This function passes the event to my map object. You could actually pass
//it to any objects in the app that you would like. Also note that I am
//getting the mouse coords from the flex app vs the actual browser. This keeps
//everything local.
public function HandleMouseWheel(event:Object): void {
var mEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false,
this.contentMouseX, this.contentMouseY, map,
event.ctrlKey, event.altKey, event.shiftKey,
false, -Number(event.delta));
map.dispatchEvent(mEvent);
}