2 Replies Latest reply on Oct 30, 2008 9:07 AM by Newsgroup_User

    Can I make a copy of an AdvancedDataGrid Item Renderer?

    ericbelair Level 1
      I have manual drag-and-drop functionality built in to my AdvancedDataGrid (ADG). Right now, I am building my own custom drag proxy using a Container instance and grabbing the text to use from the "selectedItem" property. This creates a suitable image to drag. However, what I'd really like to do is have the drag proxy look exactly like the item renderer of the item I'm dragging. I don't want the whole row, though, only one cell - that's why I can't use the ADG's "dragImage" property. When I run the code below to attempt to make a copy of the itemRenderer instance, the itemRenderer in the ADG for the source item is cleared out - the label disappears. Is there some way to make just a "copy" of the itemRenderer instance, so that it doesn't disappear from the ADG?
        • 1. Re: Can I make a copy of an AdvancedDataGrid Item Renderer?
          Level 7

          "ericbelair" <webforumsuser@macromedia.com> wrote in message
          news:gecebe$17j$1@forums.macromedia.com...
          >I have manual drag-and-drop functionality built in to my AdvancedDataGrid
          > (ADG). Right now, I am building my own custom drag proxy using a Container
          > instance and grabbing the text to use from the "selectedItem" property.
          > This
          > creates a suitable image to drag. However, what I'd really like to do is
          > have
          > the drag proxy look exactly like the item renderer of the item I'm
          > dragging. I
          > don't want the whole row, though, only one cell - that's why I can't use
          > the
          > ADG's "dragImage" property. When I run the code below to attempt to make a
          > copy
          > of the itemRenderer instance, the itemRenderer in the ADG for the source
          > item
          > is cleared out - the label disappears. Is there some way to make just a
          > "copy"
          > of the itemRenderer instance, so that it doesn't disappear from the ADG?
          >
          > // This is the container I use for my dragProxy
          > var proxyBox:VBox = new VBox();
          >
          > for each (var item:Object in this.selectedItems)
          > {
          > var selectedItemRenderer:IListItemRenderer =
          > super.itemToItemRenderer(item);
          >
          > proxyBox.addChild(DisplayObject(selectedItemRenderer));
          > }

          The itemRenderer is made by the ADG using the ClassFactory of the
          itemRenderer class.

          I think you can search for the appropriate ClassFactory for that column,
          then make a new renderer from that Factory. Set its data and/or listData to
          the same as the existing renderer.

          This might look something like this:

          var factory:IFactory;
          var renderer:IListItemRenderer;
          //populate factory with the appropriate renderer factory
          //you need to do this part
          factory=?;
          renderer = factory.getInstance();
          renderer.data=selectedItemRenderer.data;
          renderer.listData=selectedItemRenderer.listData;
          proxyBox.addChild(DisplayObject(renderer));

          You also might find that you can shortcut this by using new
          (getDefinitionByName(selectedItemRenderer.className)) instead of the
          factory.


          HTH;

          Amy


          • 2. Re: Can I make a copy of an AdvancedDataGrid Item Renderer?
            -Hob Level 1
            Your best option here is probably to take a bitmap snapshot of the renderer, and add that to the proxyBox. If you add an actual Flex component, then you're forcing the display list to invalidate repeatedly while the object is being dragged. You'll get much better performance by just snapshotting the renderer. Something like this:

            for each (var item:Object in this.selectedItems)
            {
            var selectedItemRenderer:IListItemRenderer = super.itemToItemRenderer(item);

            var bitmapData:BitmapData = new BitmapData();
            bitmapData.draw(selectedItemRenderer);
            var bitmap:Bitmap = new Bitmap(bitmapData);
            proxyBox.addChild(bitmap);
            }