我想从AIR应用程序内部和外部删除HTMl组件中的内容。 从应用程序外部删除工作正常但我不能从List中删除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)"
-->
答案 0 :(得分:0)
也许尝试分离两个dragDrops。适合我的东西适合你的代码(没有经过测试,只是更改了函数名称等。)
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。