Tuesday, October 16, 2007

Add Listeners to ImageProxy used in mx.managers.DragManager

Ran into another problem on my "Houngan" Project.

I want to drag an Image using DragManager.
And I applied imageProxy in the doDrag function and it works fine.

However, I want to hide the original image, which remains at the position it located, when I dragging the imageProxy.
So I tried the following steps:


  1. click on the original image, broadcast mouse down event
  2. execute the onMouseDown function, hide the image.
  3. make an imageProxy
  4. execute DragManager.doDrag function and move the imageProxy by following
DragManager.doDrag(initiator, ds, event, imageProxy, 0, 0, 1, true);

Yes I can hide the original image and drag the imageProxy, but the release of imageProxy doesn't resume the original image's visible stage. There is no event broadcasted from DragManager on this as far as I know. (Please kindly tell me if you do know one ^^)

I went over the source code of DragManager and discover there is a imageProxy variable in DragManagerImpl.as
And whenever endDrag is called, the imageProxy is removed from the parent container. So there is a way:


  1. click on the original image, broadcast mouse down event
  2. execute the onMouseDown function, hide the image.
  3. make an imageProxy and add event listener to it for the Event.REMOVED event.
  4. execute DragManager.doDrag function
  5. execute listener handler when Event.REMOVED is detected from imageProxy.

So that's the trick =)

No comments: