lista de chispas flexibles Arrastra y suelta un elemento en un componente de lienzo de chispas

i have a spark list that displays a list of images that represent products. i am trying to implement a drag and drop functionality that allows the user to drag the products he wants to buy from the list to canvas area where he can see the products he choose before buying them. i am using the code below but i cannot figure out what is wrong with it , it seems that i am unable to use the list item as a draginitiator, can any one help please:

private function onMouseDown( event : MouseEvent ) : void {

                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> 

preguntado el 04 de diciembre de 12 a las 04:12

1 Respuestas

I 'm thinking you need add drag initiator should be the item renderer that you are dragging rather than the entire List control. Not list.selectedItem that simple object that is not like UIComponent or VisualElement you have to point some ui component like group.

Respondido el 04 de diciembre de 12 a las 05:12

can you give an example because i do not know how can i pass my ui component to the draginitiator, also the problem is my list contains the names of the imagee and it loads the images in the run time so list.selecteditem returns a srting - karim sroor

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.