2009-12-21 21 views
0

我正在從TileList拖動到自定義組件。我想知道在我接受之前拖着什麼。如何在DragEvent中設置用於「event.dragSource.formats」的「格式」?如何設置用於在列表控件上拖放的「格式」?

編輯澄清: 當您在TileList上設置「dragEnabled = true」時,它會照顧拖動源的東西,但它使用「items」作爲DragEvent的格式。我正在尋找一種方法讓TileList使用正確的格式。

+1

你能張貼您的測試案例? – Patrick 2010-03-05 08:02:33

回答

0

嘿,這是一個很大的問題,相當複雜。由於Flex主要由Adobe開發,因此他們沒有足夠的權力/資源/資金來支持這樣的邊緣/定製案例。如果他們只分散了Flex的發展!我也不得不處理這個問題。它歸結爲Flex將特定數據源「類型」硬編碼到ListBase source中,因此您無法更改類型。這是好的和壞的......查看該ListBase類中的所有drag[Type]Handler方法,看看發生了什麼。

我們所需要做的就是攔截DragEvent.DRAG_START事件並致電event.stopImmediatePropagation()(幸運的是flex會聽那個!)。下面是一個例子程序:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml"> 

    <mx:Script> 
     <![CDATA[ 

      import mx.events.DragEvent; 
      import mx.managers.DragManager; 

      protected function updateDragSource():void 
      { 
       selected = !selected; // flip; 
       sourceType = selected ? "mySource" : "items";; 
      } 

      protected function dragEnterHandler(event:DragEvent):void 
      { 
       if (!event.dragSource.hasFormat(sourceType)) 
        event.stopImmediatePropagation(); 
      } 

     ]]> 
    </mx:Script> 

    <mx:Boolean id="selected"/> 
    <mx:String id="sourceType">items</mx:String> 

    <mx:TileList id="list" width="100%" height="100%" labelField="name" 
     dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" 
     dragEnter="dragEnterHandler(event)"> 
     <mx:dataProvider> 
      <mx:ArrayCollection> 
       <mx:Object name="one"/> 
       <mx:Object name="two"/> 
       <mx:Object name="three"/> 
       <mx:Object name="four"/> 
      </mx:ArrayCollection> 
     </mx:dataProvider> 
    </mx:TileList> 

    <mx:Label text="Change Drag Source Type:"/> 
    <mx:Button id="button" click="updateDragSource()" label="{sourceType}"/> 
</mx:Application> 

這給你檢查的基礎,如果dragSource.hasFormat返回真/假。如果你想改變dragSource的格式,你將不得不擴展TileList並覆蓋所有的的拖動方法:/。 itemsorderedItems被硬編碼到ListBase中,所以你不能輕易改變格式。

您可以使用自己的格式的唯一方法是不使用任何ListBase擴展類,並實現您自己的拖放系統。它沒有那麼壞。究其原因是因爲,如果你考慮在ListBase中所有拖動事件處理程序,他們有這樣的事情:

var dragSource:DragSource = event.dragSource; 
if (!dragSource.hasFormat("items") && !dragSource.hasFormat("orderedItems")) 
    return; 

所以,如果他們沒有這種格式,它不會讓你拖。

希望幫助, 蘭斯

+0

因此,沒有簡單的方法將格式從「項目」更改爲「myStuff」? – ablerman 2010-03-05 17:36:02

+0

nope,而不是列表類。請查看openflux如何在其拖放控制器中實現自定義拖放處理程序:http://code.google.com/p/openflux/source/browse/trunk/OpenFlux/com/openflux/controllers/DragListController.as ?規格指標爲svn192&R = 192。他們從mouseMove事件創建自己的DragSource,並且他們的DropListController處理檢查格式。檢查出來。 – 2010-03-06 01:20:48

-1

formats屬性是一個數組,因此您可以使用數組函數來訪問它。我認爲它更多你想要閱讀的東西。所以你滴處理程序會像

如果格式是「瓦列表項」,然後做降statment,否則拒絕降

相關問題