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.
-
Categories
-
Archives
April 8th, 2008 at 7:31 pm
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.
April 20th, 2008 at 1:42 am
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?
May 6th, 2008 at 9:38 am
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!
May 22nd, 2008 at 3:20 pm
@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.
June 20th, 2008 at 7:52 pm
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
June 21st, 2008 at 5:21 am
@Thanos – Thanks for the additional fix. It should prove useful for people.
January 10th, 2009 at 10:11 am
[...] 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 [...]