0

我有一个自定义的dragImage(一个带有边框和标签的简单容器),默认alpha值为0.5

拖动源是一个火花 DataGrid dropTarget 是一个带有表单的 BorderContainer

在 dropTarget 的 onDragEnter 处理程序中,我想将 dragImage alpha 设置为 1,以便视觉反馈该组件是有效的 dropTarget。

我找不到在处理程序中访问 dragImage 的方法:

private function onDragEnterActivity(ev:DragEvent):void {
            if (ev.dragSource.hasFormat('dragActivity')) {
                //i would like to access the dragImage here to set its alpha to 1
                var dropTarget:BorderContainer = BorderContainer(ev.currentTarget);
                DragManager.acceptDragDrop(dropTarget);
            }
        }

似乎在 doDrag 函数中定义(或默认值)后的 alpha 值修复

4

2 回答 2

1

查看 DragManager 源代码,我找到了使用 DragManager 的 mx_internal get dragProxy 来获取 dragImage 的解决方案

public namespace mx_internal="http://www.adobe.com/2006/flex/mx/internal";
        private function onDragEnter(ev:DragEvent):void {
            if (ev.dragSource.hasFormat('trackingDrag')) {

                var dP:IFlexDisplayObject = DragManager.mx_internal::dragProxy;
                dP.alpha = 1;
                var dropTarget:BorderContainer = BorderContainer(ev.currentTarget);
                DragManager.acceptDragDrop(dropTarget);
            }
        }
        private function onDragExit(ev:DragEvent):void {
            var dP:IFlexDisplayObject = DragManager.mx_internal::dragProxy;
            dP.alpha = 0.5;
        }

我用

public namespace mx_internal="http://www.adobe.com/2006/flex/mx/internal";

因为它是一个mxml文件

在 ActionScript 类中,它应该是

import mx.core.mx_internal; 
use namespace mx_internal;
于 2013-05-02T08:49:12.087 回答
0

这是我的解决方案,它有效!

在此处输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init(event)">
<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.core.IUIComponent;
        import mx.events.DragEvent;
        import mx.events.FlexEvent;
        import mx.managers.DragManager;

        [Bindable]private var dp:ArrayCollection = new ArrayCollection();

        protected function init(event:FlexEvent):void
        {
            for (var i:int = 0; i < 3; i++)
            {
                var label:Object = new Object();
                label.title = "Hello_" + i.toString();
                dp.addItem(label);
            }
        }

        private function onDragEnter(event:DragEvent):void
        {

            event.preventDefault();

            DragManager.acceptDragDrop(event.target as IUIComponent);
            DragManager.showFeedback(DragManager.LINK);

            var borderContainer:BorderContainer = event.currentTarget as BorderContainer;
            borderContainer.alpha = 1.0;
        }

        private function onDragOver(event:DragEvent):void
        {
            event.preventDefault(); 
        }

        protected function onDragDrop(event:DragEvent):void
        {
            try 
            {
                var borderContainer:BorderContainer = event.currentTarget as BorderContainer;
                borderContainer.alpha = 0.1;

                var dataObj:Object = event.dragSource.dataForFormat("itemsByIndex")[0] as Object;

                var la:Label = new Label();
                la.text = dataObj.title;
                trace();

                bcMain.addElement(la);
            }
            catch (err:Error)
            {                           
            }
        }

    ]]>
</fx:Script>
<s:HGroup x="20" y="20" height="100">
    <s:VGroup width="200" height="100%">
        <s:Label text="From:"/>

        <s:List id="srclist" dataProvider="{dp}" 
                width="100%" height="100%"
                allowMultipleSelection="true"
                dragEnabled="true"
                dragMoveEnabled="true">
            <s:itemRenderer>
                <fx:Component>
                    <s:ItemRenderer>
                        <s:Label text="{data.title}"/>
                    </s:ItemRenderer>
                </fx:Component>
            </s:itemRenderer>
        </s:List>
    </s:VGroup>

    <s:Spacer width="20"/>

    <s:VGroup width="200" height="100%">
        <s:Label text="To:"/>
        <s:BorderContainer 
            id="bcMain" 
            width="100%" 
            height="100%" 
            borderStyle="solid" 
            dragEnter="onDragEnter(event)" 
            dragOver="onDragOver(event)" 
            dragDrop="onDragDrop(event)" 
            backgroundImage="@Embed(source='/assets/pic/sunset.jpg')" 
            alpha="0.1">
            <s:layout>
                <s:VerticalLayout/>
            </s:layout>
        </s:BorderContainer>
    </s:VGroup>
</s:HGroup>

</s:Application>
于 2013-04-30T18:51:09.520 回答