2

我用于我的闪存应用程序外部触摸输入。我通过 as3 的 TUIO 库接收来自触摸面板的信号(https://code.google.com/p/tuio-as3/

我有时会遇到问题,然后 TuioManager 错误地检测到必须接收触摸输入的对象。

private function getTopDisplayObjectUnderPoint(point:Point):DisplayObject {
    var targets:Array =  stage.getObjectsUnderPoint(point);
    var item:DisplayObject = (targets.length > 0) ? targets[targets.length - 1] : stage;

    if (this.touchTargetDiscoveryMode == TOUCH_TARGET_DISCOVERY_MOUSE_ENABLED) {
        while (targets.length > 0) {
            item = targets.pop() as DisplayObject;
            //ignore debug cursor/object/blob and send object under debug cursor/object/blob
            if ((item is ITuioDebugCursor || item is ITuioDebugBlob || item is ITuioDebugObject || item is ITuioDebugTextSprite) && targets.length > 0) {
                continue;
            }
            if (item.parent != null && !(item is InteractiveObject)) item = item.parent;
            if (item is InteractiveObject) {
                if ((item as InteractiveObject).mouseEnabled) return item;
            }
        }
        item = stage;
    }
    else if (this.touchTargetDiscoveryMode == TOUCH_TARGET_DISCOVERY_IGNORELIST) {
        while (targets.length > 0) {
            item = targets.pop();
            //ignore debug cursor/object/blob and send object under debug cursor/object/blob
            if ((item is ITuioDebugCursor || item is ITuioDebugBlob || item is ITuioDebugObject || item is ITuioDebugTextSprite) && targets.length > 0) {
                continue;
            }
            if (!bubbleListCheck(item)) return item;
        }
        item = stage;
    }

    return item;
}

我用过this.touchTargetDiscoveryMode == TOUCH_TARGET_DISCOVERY_MOUSE_ENABLED

此函数不使用mouseChildren属性。

例如,我在 fxg 图形中使用世界地图,我想禁用它的所有子项:worldMap.mouseChildren = false;

但是如果我使用系统鼠标输入,它就可以工作,但不能用于 TUIO。函数的结果getTopDisplayObjectUnderPoint将是子影片剪辑之一。在跟踪中,我看到的层次结构如下:

worldMap
    MovieClip
        ....
           MovieClip

是的,我可以递归地mouseEnabled = falseworldMap. 它只能解决这个问题,但在更全局的情况下不能解决错误的对象选择问题。

我试图修改这个函数并写了两个辅助函数:

private function isMouseChildrenEnabled(obj:DisplayObject):Boolean {
    if (obj.parent == null) {
        return true;
    }
    return obj.parent.mouseChildren && isMouseChildrenEnabled(obj.parent);
}

private function findMouseEnabledObject(obj:InteractiveObject):InteractiveObject
{
    if (obj.mouseEnabled && isMouseChildrenEnabled(obj))
        return obj;
    return obj.parent ? findMouseEnabledObject(obj.parent) : null;
}

private function getTopDisplayObjectUnderPoint(point:Point):DisplayObject {
    var targets:Array =  stage.getObjectsUnderPoint(point);
    var item:DisplayObject = (targets.length > 0) ? targets[targets.length - 1] : stage;

    if(this.touchTargetDiscoveryMode == TOUCH_TARGET_DISCOVERY_MOUSE_ENABLED){
        while(targets.length > 0) {
            item = targets.pop() as DisplayObject;
            //ignore debug cursor/object/blob and send object under debug cursor/object/blob
            if((item is ITuioDebugCursor || item is ITuioDebugBlob || item is ITuioDebugObject || item is ITuioDebugTextSprite) && targets.length > 0){
                continue;
            }
            if (item.parent != null && !(item is InteractiveObject)) item = item.parent;
            if (item is InteractiveObject) {
                var io:InteractiveObject = findMouseEnabledObject(item as InteractiveObject);
                if (io) return io;
            }
        }
        item = stage;
    } else if (this.touchTargetDiscoveryMode == TOUCH_TARGET_DISCOVERY_IGNORELIST) {
        while(targets.length > 0) {
            item = targets.pop();
            //ignore debug cursor/object/blob and send object under debug cursor/object/blob
            if((item is ITuioDebugCursor || item is ITuioDebugBlob || item is ITuioDebugObject || item is ITuioDebugTextSprite) && targets.length > 0){
                continue;
            }
            if (!bubbleListCheck(item)) return item;
        }
        item = stage;
    }

    return item;
}

但是在新修复之后,我们有新的错误:(如果我使用 flex 拖放,我会看到错误。在拖放期间,flex 显示拖动的图像并且 tuio 检测到错误的放置目标。在 trace stage.getObjectsUnderPoint()中,我看到如下内容:

[n] - image (mouseEnabled=true, mouseChildren=true)
   parent: embed_swf_drag_cursor... (mouseEnabled=false, mouseChildren=false)
      parent: application_systemManager... (mouseEnabled=true, mouseChildren=true)
          parent: stage
[n-1] - borderContainer (mouseEnabled=true, mouseChildren=true) - it is my drop target

结果我有 systemManager 作为目标,但我需要 BorderContainer。

如何正确找到用户输入的启用对象?

PS 在 Linux 和 Windows 闪存播放器上测试。

更新 13.11

我试图编写在点下启用对象的函数:

private function getTopEnabledObject(object:DisplayObjectContainer, hitPoint:Point):InteractiveObject
{
    if (!object.mouseChildren)
        return  null;
    var child:DisplayObject;
    for (var i:int = object.numChildren - 1; i >= 0; i--)
    {
        child = object.getChildAt(i);
        if (child.visible && child is InteractiveObject && child.hitTestPoint(hitPoint.x, hitPoint.y, true))
        {
            if (child is DisplayObjectContainer)
            {
                var target:InteractiveObject = getTopEnabledObject(child as DisplayObjectContainer, hitPoint);
                if (target)
                    return target;
            }
            if ((child as InteractiveObject).mouseEnabled)
                return child as InteractiveObject; 
        }
    }
    return null;
}

它在 5-10 次中缓慢工作。我在很短的时间内多次接触后崩溃了。

4

1 回答 1

0

你这样做的方式看起来是正确的。我唯一要纠正的是,在 isMouseChildrenEnabled 中,您可以在第一个mouseChildren = false处停止并返回 false。

如果 Flex 添加拖动对象的图像,您将始终将其作为顶部目标。您必须为它编写一个特殊情况。

于 2012-11-09T23:22:59.033 回答