views:

13

answers:

1

Hi,

I'm doing the drag an drop of an ItemRenderer manually (DataGrid) and want to know how to generate a custom DragProxy of a component that hasn't been added to the display list.

I tried something like this but didn't work:

   private function doDrag(event:MouseEvent):void
   {
    var dragSource:DragSource = new DragSource();
    dragSource.addData(data, 'dnd_format');

    //var bm:Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(this));
    var btn:Button = new Button();
    btn.label = 'New Button';
    var bm:Bitmap = new Bitmap(ImageSnapshot.captureBitmapData(btn));

    var dragProxy:Image = new Image();
    dragProxy.source = bm;
    DragManager.doDrag(this, dragSource, event, dragProxy,0,0, 0.6);
   }

So, I want to be able to create the DragProxy using a component, the button is just an example. Any ideas?

+1  A: 

My guess is that this is not working because you are trying to get a bitmap from a component that was just created and has not been added to the stage. I would try testing this code with using an embedded image as the drag proxy first. If that works, then try getting a bitmap from a component that exists on the stage. My guess is that both cases will work.

Wade Mueller
yeap, both cases work. How can I take the snapshot of a component that has not been added to a display list?
fast-dev
I don't think you'll be able to do that because the component does not draw itself until later in the component lifecycle. In other words, you can't get a bitmap from a component that has not had a chance to be added to the display list and draw itself first. If the new component is one that you actually want to add to the display list, you can use the callLater method to get your snapshot. That method adds a specified method call to the end of the event queue, giving your new component a chance to set itself up and draw itself before you grab a bitmap for your proxy. Hope that helps.
Wade Mueller
thanks. What I was think as something similar to what Fex uses for printing. It kind of load the components in a invisible container to generate the snapshot...
fast-dev