0

我想从 AIR 应用程序内部和外部将内容放入 HTMl 组件中。从应用程序外部删除工作正常,但我不能从列表中删除 stuf,调用 acceptDragDrop 没有视觉效果,也没有功能效果,不会调度 drop 事件。我尝试只使用 DragManager,然后只使用 NativeDragManager 但效果相同。我不明白缺少什么,为什么该方法不接受丢弃。

我有一些示例代码(有一些实验被注释掉了)

<?xml version="1.0" encoding="utf-8"?>

        private function get testData():ArrayCollection{
            var a:ArrayCollection=new ArrayCollection;
            var arr:Array=[{label:"T1"},{label:"T2"},{label:"T3"}];
            a.source=arr;
            return a;
        }

        protected function htmlSummary_dragDropHandler(event:DragEvent):void
        {
            if(event.dragInitiator is List){
                var tree:List=event.dragInitiator as List;
                var item:*=tree.selectedItem;
                trace(item);

            }
            trace("DRAG dROP");
        }
        private var dragEvent:DragEvent;
        protected function htmlSummary_dragEnterHandler(event:DragEvent):void
        {
            this.dragEvent=event;
            trace("DRAG ENTER");
        }

        protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
        {
            this.htmlSummary.htmlLoader.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER,htmlSummary_nativeDragEnterHandler,true,0,true);
            this.htmlSummary.htmlLoader.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP,htmlSummary_nativeDragDropHandler);

        }

        protected function htmlSummary_dragCompleteHandler(event:DragEvent):void
        {
            this.dragEvent=null;
            trace("DRAG COMPLETE");
        }

        protected function htmlSummary_dragExitHandler(event:DragEvent):void
        {
            this.dragEvent=null;
            trace("drag exit");
        }

        protected function htmlSummary_nativeDragEnterHandler(event:NativeDragEvent):void
        {
        //  if(dragEvent)
            NativeDragManager.acceptDragDrop(InteractiveObject(event.currentTarget));
            trace("native drag enter");
        }

        protected function htmlSummary_nativeDragDropHandler(event:NativeDragEvent):void
        {
            if(dragEvent){
                var item:*;
                if(dragEvent.currentTarget is List){
                    item=List(dragEvent.currentTarget).selectedItem;
                    if(item)
                        Alert.show(item.label);
                }
            }
            trace("native drag drop");
        }

    ]]>
</fx:Script>

<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<s:List width="130" height="100%" dataProvider="{testData}" dragEnabled="true"/>
<mx:HTML id="htmlSummary" location="http://google.com" width="100%" height="100%" 
        />
         <!--
nativeDragEnter="htmlSummary_nativeDragEnterHandler(event)"
nativeDragDrop="htmlSummary_nativeDragDropHandler(event)"
         dragComplete="htmlSummary_dragCompleteHandler(event)"
         dragDrop="htmlSummary_dragDropHandler(event)"  
        dragEnter="htmlSummary_dragEnterHandler(event)"
        dragExit="htmlSummary_dragExitHandler(event)"
        -->

4

1 回答 1

0

也许尝试分离两个拖放。适用于您的代码的适合我的东西(尚未测试,但只是更改了函数名称等)

protected function htmlSummary_dragOverHandler(event:DragEvent):void
{ 

       if(event.dragSource.hasFormat('treeItems')){
                    DragManager.showFeedback(DragManager.COPY); //dropped from list             
                    DragManager.acceptDragDrop(InteractiveObject(event.currentTarget));
            }               
            else if(event.dragSource.hasFormat('air:file list')){ //dropped from fileSystem
                DragManager.showFeedback(DragManager.COPY);
                NativeDragManager.acceptDragDrop(InteractiveObject(event.currentTarget));
            }
       }

}

    protected function htmlSummary_dragDropHandler(event:DragEvent):void
    {
        if(event.dragSource.hasFormat('treeItems')){                    
           var item:* = event.dragSource.dataForFormat("treeItems")[0];
        } else if (event.dragSource.hasFormat('air:file list')){
            var item:* = event.dragSource.dataForFormat("air:file list")[0];
        }

    }

监听的事件只有常规的 DragEnter 和 DragOver 而不是 NativeDrag。

于 2013-06-17T07:34:23.437 回答