Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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_Apache Flex_Flex4 - Fatal编程技术网

Actionscript 3 列表项渲染器拖过检测

Actionscript 3 列表项渲染器拖过检测,actionscript-3,apache-flex,flex4,Actionscript 3,Apache Flex,Flex4,如图所示,假设将item1的List1拖到item iv的List2,我希望item iv检测拖拽状态和hightlight本身,那么如何实现它?将一个MouseeEvent.MOUSE\u置于侦听器上,检查您是否正在拖拽任何内容,如果是,event.target高亮显示。将一个MouseEvent.MOUSE\u滑过侦听器附加到每个列表元素,该侦听器检查您是否正在拖动任何内容,如果是这样,event.target高亮显示。以下是我的解决方案和代码: 对于列表2: <s:List item


如图所示,假设将item1的List1拖到item iv的List2,我希望item iv检测拖拽状态和hightlight本身,那么如何实现它?

将一个
MouseeEvent.MOUSE\u置于
侦听器上,检查您是否正在拖拽任何内容,如果是,
event.target
高亮显示。

将一个
MouseEvent.MOUSE\u滑过
侦听器附加到每个列表元素,该侦听器检查您是否正在拖动任何内容,如果是这样,
event.target
高亮显示。

以下是我的解决方案和代码: 对于列表2

<s:List
itemRenderer="components.MyRenderer"
dragEnter="myDragEnterHandler(event)"
dragOver="myDragOverHandler(event)"
dragExit="myDragExitHandler(event)">
<fx:Script>
    <![CDATA[
        private function myDragEnterHandler(event:DragEvent):void {
            //we shoudld make List2 be drop target
            DragManager.acceptDragDrop(e.currentTarget as IUIComponent);              
        }

        private function myDragOverHandler(event:DragEvent):void {
            var dropIndex:int = calDropIndex(event);
            var element:MyRenderer= calDropItem(dropIndex);
            //undo highlight if there is last over item
            if(lastOverItem) {
               lastOverItem.undoHighlight();            
            }
            //remember the last highlight one and highlight it
            lastOverItem = element;     
            element.highlight(); 
        }

        private function myDragExitHandler(event:DragEvent):void {
             var dropIndex:int = calDropIndex(event);
             var element:MyRenderer= calDropItem(dropIndex);
             element.undoHighlight(); 
        }

        private function calDropIndex(event:DragEvent):int {
             var dropLocation:DropLocation = 
                 event.currentTarget.layout.calculateDropLocation(event);
             var dropIndex:int = dropLocation.dropIndex;
             return dropIndex;
       }

       private function calDropItem(dropIndex:int):MyRenderer{
           var element:IVisualElement;
           if (layout.useVirtualLayout) {
            element = layout.target.getVirtualElementAt(dropIndex);
           } else {
            element = layout.target.getElementAt(dropIndex);
           }
           return element as MyRenderer;
      }
    ]]>
</fx:Script>
</S:List>

这是我的解决方案和代码: 对于列表2

<s:List
itemRenderer="components.MyRenderer"
dragEnter="myDragEnterHandler(event)"
dragOver="myDragOverHandler(event)"
dragExit="myDragExitHandler(event)">
<fx:Script>
    <![CDATA[
        private function myDragEnterHandler(event:DragEvent):void {
            //we shoudld make List2 be drop target
            DragManager.acceptDragDrop(e.currentTarget as IUIComponent);              
        }

        private function myDragOverHandler(event:DragEvent):void {
            var dropIndex:int = calDropIndex(event);
            var element:MyRenderer= calDropItem(dropIndex);
            //undo highlight if there is last over item
            if(lastOverItem) {
               lastOverItem.undoHighlight();            
            }
            //remember the last highlight one and highlight it
            lastOverItem = element;     
            element.highlight(); 
        }

        private function myDragExitHandler(event:DragEvent):void {
             var dropIndex:int = calDropIndex(event);
             var element:MyRenderer= calDropItem(dropIndex);
             element.undoHighlight(); 
        }

        private function calDropIndex(event:DragEvent):int {
             var dropLocation:DropLocation = 
                 event.currentTarget.layout.calculateDropLocation(event);
             var dropIndex:int = dropLocation.dropIndex;
             return dropIndex;
       }

       private function calDropItem(dropIndex:int):MyRenderer{
           var element:IVisualElement;
           if (layout.useVirtualLayout) {
            element = layout.target.getVirtualElementAt(dropIndex);
           } else {
            element = layout.target.getElementAt(dropIndex);
           }
           return element as MyRenderer;
      }
    ]]>
</fx:Script>
</S:List>


它不适合这种情况。我只希望当List1项拖动到它上面时,List2的项被高亮显示。如果将MouseEvent.MOUSE_附加到上方,列表2的项目将高亮显示,即使它不是由拖动行为触发的。@Vesper,这是我的解决方案。在列表2中,我在两个事件处理程序中侦听DRAG_OVER和DRAG_DROP事件,计算放置索引,使用layout.target.getElementAt()获取列表项,然后调用item.highlight()。但我还遇到了另一个问题,如果在仍然拖动的情况下更改下拉项(例如从第四项到第三项),如何撤消前一项的突出显示?@Allan,你能看看最新的评论吗?请听滑鼠退出?无论如何,它都会迫使您的列表项取消显示。@Vesper,我明白了,您可以看一下:)。它不适合这种情况。我只希望当List1项拖动到它上面时,List2的项被高亮显示。如果将MouseEvent.MOUSE_附加到上方,列表2的项目将高亮显示,即使它不是由拖动行为触发的。@Vesper,这是我的解决方案。在列表2中,我在两个事件处理程序中侦听DRAG_OVER和DRAG_DROP事件,计算放置索引,使用layout.target.getElementAt()获取列表项,然后调用item.highlight()。但我还遇到了另一个问题,如果在仍然拖动的情况下更改下拉项(例如从第四项到第三项),如何撤消前一项的突出显示?@Allan,你能看看最新的评论吗?请听滑鼠退出?无论如何,它都会迫使您的列表项取消显示。@Vesper,我明白了,您可以看一看:)。您的问题的确切答案在于您的问题的确切答案在于