2

我有一个火花列表,其中显示代表产品的图像列表。我正在尝试实现一个拖放功能,该功能允许用户将他想要购买的产品从列表中拖到画布区域,在那里他可以在购买之前看到他选择的产品。我正在使用下面的代码,但我无法弄清楚它有什么问题,似乎我无法将列表项用作拖动器,任何人都可以帮忙:

私有函数 onMouseDown(事件:鼠标事件):无效 {

                var list:List = List(event.currentTarget);
                var dragInitiator:Image = Image (list.selectedItem);
                var source : DragSource = new DragSource();
                source.addData(dragInitiator, "img");
                DragManager.doDrag(dragInitiator, source, event);

        }



        protected function canvas1_dragEnterHandler(event:DragEvent):void
        {

                DragManager.acceptDragDrop(Canvas(event.currentTarget));


        }

        protected function canvas1_dragDropHandler(event:DragEvent):void
        {
            Image(event.dragInitiator).x = 
                Canvas(event.currentTarget).mouseX;
            Image(event.dragInitiator).y = 
                Canvas(event.currentTarget).mouseY;  }

    <fx:Model id="categoriesModel" source="Data/Categories.xml"/>
    <s:ArrayList id="CategoriesCollection" source="{categoriesModel.Category}"/>

    <fx:Model id="productsModel" source="Data/Products.xml"/>
    <s:ArrayList id="ProductsCollection" source="{productsModel.Product}" />


</fx:Declarations>

<s:VGroup gap="5"  horizontalAlign="center">

    <s:HGroup gap="5">

        <Components:PROExpressLogo/>
        <s:List id="categoryList"   scroller="{null}"  visible="true"
                itemRenderer="Renderers.categoryItemRenderer" width="700"  borderAlpha="0" 
                change="categoryList_changeHandler(event)">
            <s:layout>
                <s:HorizontalLayout/>
            </s:layout>
        </s:List>   

    </s:HGroup>

    <s:List id="productList"   scroller="{null}" contentBackgroundAlpha="0.4" contentBackgroundColor="0xabcdef"
            itemRenderer="Renderers.productItemRenderer" width="880"  borderAlpha="0" visible="true" horizontalCenter="0" 
             dragEnabled="false" mouseDown="onMouseDown(event)"  
            >   
        <s:layout>
            <s:HorizontalLayout/>
        </s:layout>
    </s:List>

    <s:HGroup gap="20">
        <s:Group>
                <s:Image id="planImage" width="500" height="300" horizontalCenter="0"  
                         toolTip="Drag your items on your Plan and drop them were you plan to install them" 
                         />

                <mx:Canvas width="500" height="300" backgroundAlpha="0.1"
                           backgroundColor="#abcdef" borderColor="#abcdef" borderStyle="inset"
                           contentBackgroundColor="#abcdef" cornerRadius="10"
                           dragDrop="canvas1_dragDropHandler(event)"
                           dragEnter="canvas1_dragEnterHandler(event)" dropShadowVisible="true"
                           horizontalCenter="0"/>
        </s:Group>
                <s:List id="cart" width="200" height="300"/>
    </s:HGroup> 
4

1 回答 1

0

我认为您需要添加拖动启动器应该是您拖动的项目渲染器,而不是整个 List 控件。不是list.selectedItem那种简单的对象,不像UIComponent or VisualElement你必须指向一些 ui 组件,比如group.

于 2012-12-04T05:50:24.077 回答