Flex 4 - 从列表中拖动 - Dragsource.dataForFormat(“itemsByIndex”) 为 null

发布于 2024-11-14 02:33:43 字数 2923 浏览 3 评论 0原文

预先感谢任何试图帮助我的人,

我正在使用 Flex 4,并尝试在列表之间以及列表和非列表组件之间进行拖放操作。

我有一个自定义 itemRenderer,它有一个图像和一个标签。

从图形上看,一切都很好,但是附加到我正在拖动的项目的数据每次在dragSource中都显示为空。

这是我的代码:

    <s:List dataProvider="{userInventory}" itemRenderer="renderers.InventoryItemRenderer" width="198" height="294" y="34" dragEnabled="true" dragMoveEnabled="true"  >
        <s:layout>
            <s:TileLayout />        
        </s:layout>
    </s:List>

</s:BorderContainer>
<!-- /User Inventory -->
<s:BorderContainer dragEnter="fndragEnterHandler(event);" 
                   dragOver="fndragOverHandler(event);"
                   dragDrop="fndragDropHandler(event);" includeIn="crib" x="243" y="206" width="200" height="200">
    <s:Label x="10" y="10" text="This is supposed to be a baby" width="178" height="24"/>
    <s:Label x="10" y="39" text="State:" width="42" height="19"/>
    <s:Label x="59" y="37" width="80" height="24" id="baby_state"/>

</s:BorderContainer>
private function fndragEnterHandler(event:DragEvent):void
        {

                DragManager.acceptDragDrop(IUIComponent(event.currentTarget));  
        }
        private function fndragOverHandler(event:DragEvent):void
        {

                DragManager.showFeedback(DragManager.MOVE);
        }

        private function dragOverCopyHandler(event:DragEvent):void {
            event.preventDefault();
            //if (event.dragSource.hasFormat("itemsByIndex"))
                DragManager.showFeedback(DragManager.COPY);
        }

        private function fndragDropHandler(event:DragEvent):void
        {
            //event.preventDefault();

            monsterDebugger.trace(this, event.dragSource, null, "DRAG DROP");


            var items:Vector = event.dragSource.dataForFormat("itemsByIndex") as Vector;
            var baby:Array = babyObject.source;

            monsterDebugger.trace(this, items, null, "DRAG DROP");

            items[0].baby_id = baby[0]['Baby']['id'];

            var item:Object = new Object();

            item.id = items[0].id;
            item.baby_id = items[0].baby_id;
            item.effect = JSON.decode(items[0].effect);


            sendAction(item, "baby", userFbData.id, "use_item_on_baby");



            //TextInput(event.currentTarget).text=itemsArray[0].label;
        }

这是我的 itemRenderer:

<mx:Image x="14" y="19" source="{data.image}" width="50" height="50" smoothBitmapContent="true"/>
<s:Label x="0" y="-1" text="{data.name}" fontFamily="Verdana" fontSize="12" color="#696565" width="80" height="21"/>

放置处理程序中的 items Vector 每次都会返回 null,我不太明白为什么。

我一开始以为这是因为这种特殊情况没有从 List 拖动到 List,但我也尝试了这种方式,并且 DragSource.dataForFormat("itemsByIndex") 继续返回 null。

如果有人能指出我正确的方向,我将不胜感激,两天来我一直在努力解决这个问题!

Thanks in advance for anyone who tries to help me out,

I am working with Flex 4 and am trying to get Drag and Drop working between Lists and between a List and non-list component.

I have a custom itemRenderer which has an image and a label.

Graphically everything works great but the data that is attached to the item I am dragging comes up in dragSource as null every time.

Here is my code:

    <s:List dataProvider="{userInventory}" itemRenderer="renderers.InventoryItemRenderer" width="198" height="294" y="34" dragEnabled="true" dragMoveEnabled="true"  >
        <s:layout>
            <s:TileLayout />        
        </s:layout>
    </s:List>

</s:BorderContainer>
<!-- /User Inventory -->
<s:BorderContainer dragEnter="fndragEnterHandler(event);" 
                   dragOver="fndragOverHandler(event);"
                   dragDrop="fndragDropHandler(event);" includeIn="crib" x="243" y="206" width="200" height="200">
    <s:Label x="10" y="10" text="This is supposed to be a baby" width="178" height="24"/>
    <s:Label x="10" y="39" text="State:" width="42" height="19"/>
    <s:Label x="59" y="37" width="80" height="24" id="baby_state"/>

</s:BorderContainer>
private function fndragEnterHandler(event:DragEvent):void
        {

                DragManager.acceptDragDrop(IUIComponent(event.currentTarget));  
        }
        private function fndragOverHandler(event:DragEvent):void
        {

                DragManager.showFeedback(DragManager.MOVE);
        }

        private function dragOverCopyHandler(event:DragEvent):void {
            event.preventDefault();
            //if (event.dragSource.hasFormat("itemsByIndex"))
                DragManager.showFeedback(DragManager.COPY);
        }

        private function fndragDropHandler(event:DragEvent):void
        {
            //event.preventDefault();

            monsterDebugger.trace(this, event.dragSource, null, "DRAG DROP");


            var items:Vector = event.dragSource.dataForFormat("itemsByIndex") as Vector;
            var baby:Array = babyObject.source;

            monsterDebugger.trace(this, items, null, "DRAG DROP");

            items[0].baby_id = baby[0]['Baby']['id'];

            var item:Object = new Object();

            item.id = items[0].id;
            item.baby_id = items[0].baby_id;
            item.effect = JSON.decode(items[0].effect);


            sendAction(item, "baby", userFbData.id, "use_item_on_baby");



            //TextInput(event.currentTarget).text=itemsArray[0].label;
        }

And here is my itemRenderer:

<mx:Image x="14" y="19" source="{data.image}" width="50" height="50" smoothBitmapContent="true"/>
<s:Label x="0" y="-1" text="{data.name}" fontFamily="Verdana" fontSize="12" color="#696565" width="80" height="21"/>

The items Vector in the drop handler comes back null every time and I can't quite figure out why.

I thought at first that it was because that particular case is not dragging from List to List, but I tried it that way also and the dragSource.dataForFormat("itemsByIndex") continues to return null.

If anyone can point me in the right direction I would greatly appreciate it, I've been banging my head against this for two days!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网名女生简单气质 2024-11-21 02:33:43

您转换为 Vector 可能已经使拖动源数据无效。所以尝试

var items:* = event.dragSource.dataForFormat("itemsByIndex"); 

you cast to Vector may already nullify the dragsource data. so try with

var items:* = event.dragSource.dataForFormat("itemsByIndex"); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文