【问题标题】:Flex Drag and Drop between AdvancedDataGrid with custom itemRenderer使用自定义 itemRenderer 在 AdvancedDataGrid 之间进行 Flex 拖放
【发布时间】:2011-02-26 04:43:46
【问题描述】:

我已经实现了 2 个 AdvancedDataGrid 之间的拖放,但 Flex 的默认行为使用显示所有 5 列的网格项渲染器在拖动期间显示行数据。

相反,我想在拖动过程中显示图标/图像或我自己的自定义项目渲染器 和下降。最简单的方法是什么?

有什么例子吗?

谢谢!

【问题讨论】:

    标签: apache-flex drag-and-drop itemrenderer advanceddatagrid


    【解决方案1】:

    子类AdvancedDataGrid 并覆盖一个属性:

    public class MyAdvancedDataGrid extends AdvancedDataGrid
    {
    
        public function MyAdvancedDataGrid()
        {
            super();
        }
    
        [Embed("script.png")]
        private var scriptClass:Class;
    
        override protected function get dragImage():IUIComponent
        {
            var image:Image = new Image();
            image.source = scriptClass;
            image.owner = this;
            image.moduleFactory = moduleFactory;
            return image; 
        }
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用拖动代理属性来指定图像。来自Adobe's online examples

      <?xml version="1.0"?>
      <!-- dragdrop\DandDImageProxy.mxml -->
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
      
          <mx:Script>
              <![CDATA[
                  //Import classes so you don't have to use full names.
                  import mx.managers.DragManager;
                  import mx.core.DragSource;
                  import mx.events.DragEvent;
                  import flash.events.MouseEvent;
      
                  // Embed icon image.
                  [Embed(source='assets/globe.jpg')]
                  public var globeImage:Class;
      
                  // The mouseMove event handler for the Image control
                  // initiates the drag-and-drop operation.
                  private function mouseOverHandler(event:MouseEvent):void 
                  {                
                      var dragInitiator:Image=Image(event.currentTarget);
                      var ds:DragSource = new DragSource();
                      ds.addData(dragInitiator, "img");               
      
                      // The drag manager uses the Image control 
                      // as the drag proxy and sets the alpha to 1.0 (opaque),
                      // so it appears to be dragged across the Canvas.
                      var imageProxy:Image = new Image();
                      imageProxy.source = globeImage;
                      imageProxy.height=15;
                      imageProxy.width=15;                
                      DragManager.doDrag(dragInitiator, ds, event, 
                          imageProxy, -15, -15, 1.00);
                  }
      
                  // The dragEnter event handler for the Canvas container
                  // enables dropping.
                  private function dragEnterHandler(event:DragEvent):void {
                      if (event.dragSource.hasFormat("img"))
                      {
                          DragManager.acceptDragDrop(Canvas(event.currentTarget));
                      }
                  }
      
                  // The dragDrop event handler for the Canvas container
                  // sets the Image control's position by 
                  // "dropping" it in its new location.
                  private function dragDropHandler(event:DragEvent):void {
                      Image(event.dragInitiator).x = 
                          Canvas(event.currentTarget).mouseX;
                      Image(event.dragInitiator).y = 
                          Canvas(event.currentTarget).mouseY;
                  }
              ]]>
          </mx:Script>
      
          <!-- The Canvas is the drag target --> 
          <mx:Canvas id="v1" 
              width="500" height="500"  
              borderStyle="solid" 
              backgroundColor="#DDDDDD"
              dragEnter="dragEnterHandler(event);" 
              dragDrop="dragDropHandler(event);">
      
              <!-- The image is the drag initiator. -->
              <mx:Image id="myimg" 
                  source="@Embed(source='assets/globe.jpg')" 
                  mouseMove="mouseOverHandler(event);"/> 
          </mx:Canvas>
      </mx:Application>
      

      【讨论】:

        猜你喜欢
        • 2011-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多