2009-10-14 119 views
1

我還有一個拖放問題。我在Tree組件上使用了DnD,當它在樹中有50-80個項目時它工作正常。但是,當我有100-300個物品時,簡單的拖放操作突然消耗我所有的CPU容量,並且應用程序凍結達1分鐘。Flex 3樹拖放很慢

我想這是因爲Flex試圖重繪代理dragImage,因此需要重繪所有300個節點。有沒有辦法關閉dragImage?一個簡單的帶有小矩形的光標箭頭就足以達到我的目的。

是否有其他人遇到Flex Tree組件的性能問題?

謝謝。

回答

1

我已經在Flex中使用了幾個基於列表的組件進行了拖放操作,但沒有遇到CPU容量超載或應用程序死機的任何問題。我會建議在Flex Builder中運行一個配置文件,以查看所有CPU和/或內存的使用情況,並努力解決該問題。至於拖放,我一直傾向於創建自己的拖放功能,以便我可以按照自己想要的數據來創建自己的代理映像。以下是我在開始Tree組件拖動:

override protected function mouseDownHandler(event:MouseEvent):void 
{ 
    var eventPoint:Point = new Point(event.localX, event.localY); 

    var eventPointGlobal:Point = super.localToGlobal(eventPoint); 

    mouseDownPoint = super.globalToLocal(eventPointGlobal); 

    super.mouseDownHandler(event); 
} 

// MouseMove Handler for manually initiating Drag functionality 
override protected function mouseMoveHandler(event:MouseEvent):void 
{ 
    super.mouseMoveHandler(event); 

    if (!event.buttonDown || DragManager.isDragging) 
     return; 

    /* Create a point relative to this component from the mouse 
     cursor location. */ 
    var eventPoint:Point = new Point(event.stageX, event.stageY); 

    var dragPoint:Point = super.globalToLocal(eventPoint); 

    if (!mouseDownPoint) 
     return; 

    if (Math.abs(mouseDownPoint.x - dragPoint.x) <= 4 
      || Math.abs(mouseDownPoint.y - dragPoint.y) <= 4) 
     return; 

    if (!event.target is UITextField) 
     return; 

    if (selectedItems.length == 0) 
     return; 

    var dragSource:DragSource = new DragSource(); 

    var dragProxy:DragProxyContainer = new DragProxyContainer(); // This is my custom Drag Proxy Image that I reuse throughout my application (see below) 

    dragProxy.setLabelText([selectedItem]); 

    // Initiate the Drag Event 
    DragManager.doDrag(this, dragSource, event, dragProxy, 
     -dragPoint.x+event.localX, -dragPoint.y+event.localY, 0.8); 
} 


package view 
{ 
    import mx.containers.VBox; 
    import mx.core.UITextField; 

    [Bindable] 
    public class DragProxyContainer extends VBox 
    { 
     private var textField:UITextField = new UITextField(); 

     public function DragProxyContainer() 
     { 
      super(); 

      minWidth = 150; 

      addChild(textField); 
     } 

     public function setLabelText(items:Array, labelField:String = "label"):void 
     { 
      var labelText:String; 

      var numItems:int = items.length; 

      if (numItems > 1) 
      { 
       labelText = numItems.toString() + " items"; 
      } 
      else 
      { 
       var firstItem:Object = items[0]; 

       labelText = firstItem[labelField]; 
      } 

      textField.text = labelText; 
     } 
    } 
}