Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何在点下获取顶部鼠标启用对象?_Actionscript 3_Flash_Apache Flex - Fatal编程技术网

Actionscript 3 如何在点下获取顶部鼠标启用对象?

Actionscript 3 如何在点下获取顶部鼠标启用对象?,actionscript-3,flash,apache-flex,Actionscript 3,Flash,Apache Flex,我的flash应用程序使用外部触摸输入。我通过as3()的TUIO库接收来自触摸面板的信号 我有时会遇到问题,然后TuioManager错误地检测到必须接收触摸输入的对象 private function getTopDisplayObjectUnderPoint(point:Point):DisplayObject { var targets:Array = stage.getObjectsUnderPoint(point); var item:DisplayObject =

我的flash应用程序使用外部触摸输入。我通过as3()的TUIO库接收来自触摸面板的信号

我有时会遇到问题,然后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\u TARGET\u DISCOVERY\u MOUSE\u ENABLED

此函数不使用
mouseChildren
属性

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

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

worldMap
    MovieClip
        ....
           MovieClip
是的,我可以为
worldMap
的子级递归设置所有属性
mouseEnabled=false
。它只能解决这个问题,但在更全局的情况下不能解决对象选择错误的问题

我试图修改此函数,并编写了两个助手函数:

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;
}
但经过新的修复后,我们有了新的bug:( 如果我使用flex拖放,我会看到错误。在拖放过程中,flex会显示被拖动的图像,tuio会检测到错误的拖放目标。在tracestage.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

如何正确查找用户输入的已启用对象

p.S.在Linux和Windows flash播放器上测试

更新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次。在短时间内多次触摸之后,我就崩溃了。

您的操作方式看起来是正确的。我唯一要纠正的是,在isMouseChildrenEnabled中,您可以在第一次鼠标时停止Children=false并返回false


如果Flex添加被拖动对象的图像,您将始终将其作为顶级目标。您必须为其编写一个特例。

它只解决了拖放的一个问题。我认为这将是关于event.target和event.currentTarget的另一个问题。我们在这一步中没有事件。我们尝试在此处查找事件目标。