I was sitting here at 360Flex|Milan and I had a conversation with Michael Labriola about DragManagers in AIR. We both lamented that in Flexbuilder 3 beta 2, we were able to use both the NativeDragManager and the DragManager at the same time (albeit it was a bit hacky). In an earlier post, I demonstrated a MonkeyPatch that allowed you to use the Flex DragManager inside a WindowedApplication in AIR. This was great, but you lose the ability to use Native Dragging/Dropping in your AIR app. This evening, I was finally pissed off enough to rewrite the DragManager how I think Adobe SHOULD have done it in the first place. You use the DragManager class for both Native and Flex-based drag/drop and it’ll pretty much figure out which one you wanted to use. If you’re doing manual Native dragging OUT of your app, the doDrag() method has an additional boolean value at the end to specify that it’s supposed to begin a native drag operation. I’m not going to go into a ton of detail on how it was done, but the code is posted below with view-source enabled. DragManager and SystemManager have been MonkeyPatched.  It’s been liberally commented, so hopefully you can figure it out. Post a comment if you have trouble with it or it screws up because I missed catching a bug here or there.

DualDragManagers.air

Post to Twitter

Posted by Andrew, filed under 360 Flex, AIR, MonkeyPatch. Date: April 8, 2008, 4:08 pm | 7 Comments »

7 Responses

  1. Tom Ortega Says:

    This is the kind of stuff we love about our show. Getting people together and wonderful things happen. Great job! Glad you were here to hang with Labriola and whip out some code right quick.

  2. Mario Rodrigues Says:

    Hi,

    Thank you so much for this code. I was stumbling around for a few hours before I came across your blog post. Your code works great with one exception. When I open a new Window and close it, I get the following error:

    TypeError: Error #1034: Type Coercion failed: cannot convert mx.managers::DragManagerImpl@73e8039 to mx.managers.NativeDragManagerImpl.
    at mx.managers::WindowedSystemManager/http://www.adobe.com/2006/flex/mx/internal::cleanup()[E:\dev\3.0.x\frameworks\projects\airframework\src\mx\managers\WindowedSystemManager.as:1684]

    Have you come across this before?

  3. tj Says:

    Awesome, thanks!!
    As an FYI, I was running into an inability in Flex-on-AIR to use remote images (loaded into itemRenderers in a TileList) as drag proxy images- the label would show on the proxy but not the image (the itemRenderer being a Canvas with Image and Label controls). After trying literally EVERYTHING over the past few days, this fixed the last of my problems. Hopefully, as AIR picks up, this fix will come in handy for other AIR devs!

  4. Andrew Says:

    @Mario I have not come across this bug before. I don’t usually open multiple native windows. If you find a solution, let me know.

  5. Thanos Says:

    Hello,

    i came across the same problem Mario reported (error message when closing a Window instance).
    Here is what I did to fix the problem (although not extensively tested):

    a) copy the class WindowedSystemManager.as (the one that complains about the error), under mx\managers (Same folder with SystemManager).
    b) replace Singleton.getClass(“mx.managers::IDragManager”) with
    Singleton.getClass(“mx.managers::INativeDragManager”)

    which is the name used during manager’s class registration by Andrew on patched SystemManager class.

    thanks:)
    Thanos

  6. Andrew Says:

    @Thanos – Thanks for the additional fix. It should prove useful for people.

  7. » Blog Archive » Dual Drag Managers in AIR 1.5 Says:

    [...] April, I had a blog post about how to use both the Native and Flex DragManagers at the same time by monkey-patching an AIR [...]

Leave a Comment

 
Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.