2012-12-04 88 views
2

我有一個火花列表,顯示錶示產品的圖像列表。我試圖實現拖放功能,允許用戶將他想購買的產品從列表拖到畫布區域,在那裏他可以在購買之前看到他選擇的產品。我使用下面的代碼,但我無法弄清楚它有什麼問題,似乎我無法使用列表項目作爲draginitiator,任何人都可以幫助:柔性火花列表在火花畫布組件上拖放一個項目

private function onMouseDown(event:MouseEvent) :無效 {

   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> 

回答

0

我在想你需要添加拖動啓動應該是您正在拖動項呈示而不是整個List控件。 不是list.selectedItem那個簡單的對象不像UIComponent or VisualElement你必須指出一些UI組件,如group

+0

你可以舉一個例子,因爲我不知道如何將我的UI組件傳遞給draginitiator,問題是我的列表包含imagee的名稱,它在運行時加載圖像,所以list.selecteditem返回一個srting –