I’m not really sure what Adobe has been thinking regarding DragManagers in Flex/AIR. The code makes a very basic and very WRONG assumption that in an AIR app using WindowedApplication, you will only ever want to use the NativeDragManager class. DragManager loads up a singleton class to handle drag and drop. Depending on whether your app is AIR or Flex and what your top-level container is you either get DragManagerImpl (the flex drag manager) or NativeDragManagerImpl. Unfortunately, this class has some really annoying limitations. You can’t specify an alpha level for the drag proxy. It’s hardcoded to 0.5 and there’s nothing you can do about it. Here’s what adobe has to say about it…

When a Flex application runs in Adobe® AIR™, you can control whether the application uses the Flex drag manager or the AIR drag manager. These drag managers are implemented by the classes mx.managers.DragManager (Flex drag manager) and flash.desktop.NativeDragManager (AIR drag manager).

Internally, the Flex mx.managers.DragManager class uses an implementation class to determine which drag manager to use. It uses either the Flex mx.managers.DragManagerImpl class, or the AIR mx.managers.NativeDragManagerImpl class.

By default, a Flex application defined by the <mx:Application> tag uses the Flex drag-and-drop manager, even when the Flex application runs in AIR. If you run your Flex application in AIR, and you want to take advantage of the AIR drag-and-drop manager to drag and drop items from outside of AIR, then you must configure the Flex mx.managers.DragManager class to use the AIR drag-and-drop manager.

There are three scenarios that determine which drag-and-drop manager your Flex application uses when running in AIR:

  1. Your main application file uses the <mx:Application> tag. In this scenario, you use the Flex drag-and-drop manager, and cannot drag and drop items from outside of AIR.
  2. Your main application file uses the <mx:WindowedApplication> tag. In this scenario, you use the AIR drag-and-drop manager, and can drag and drop items from outside of AIR.
  3. Your main application file uses the <mx:Application> tag, but loads the AIR drag-and-drop manager as represented by the mx.managers.NativeDragManagerImpl class. In this scenario, you use the AIR drag-and-drop manager, and can drag and drop items from outside of AIR.

Now what am I to do if I want option 4? I want all the window dressing goodness that comes with WindowedApplication like maximize, minimize, and a status bar, but I want the fully customizable Flex version of the drag manager implementation. Time to MONKEYPATCH!

The first thing you’ll need is to copy the framework classes mx.managers.SystemManager and mx.core.Version into your AIR app at the right locations.
monkeypatch1

Next, you edit one line of code in SystemManager.as so that it loads the DragManagerImpl instead of NativeDragManagerImpl. Find the method docFrameHandler. You should see a bit of code that looks like this…

    if (Capabilities.playerType == "Desktop")
    {
        Singleton.registerClass("mx.managers::IDragManager",
            Class(getDefinitionByName("mx.managers::NativeDragManagerImpl")));

        // Make this call to create a new instance of the DragManager singleton.
        // This will allow the application to receive NativeDragEvents that originate
        // from the desktop.
        // if this class is not registered, it's most likely because the NativeDragManager is not
        // linked in correctly. all back to old DragManager.
        if (Singleton.getClass("mx.managers::IDragManager") == null)
            Singleton.registerClass("mx.managers::IDragManager",
                Class(getDefinitionByName("mx.managers::DragManagerImpl")));
    }

Now change to look like this…

    if (Capabilities.playerType == "Desktop")
    {
        Singleton.registerClass("mx.managers::IDragManager",
            Class(getDefinitionByName("mx.managers::DragManagerImpl")));

Enjoy your AIR app with the Flex DragManager goodness.

Post to Twitter

Posted by Andrew, filed under AIR, as3, Flex, MonkeyPatch. Date: February 26, 2008, 8:27 pm | 1 Comment »

I just wanted to blog my initial impressions of FlexBuilder 3 after a day of use.  The IDE seems very much the same as the final beta.  There are some new feature there I know, but I haven’t really gotten into them yet.  It was nice that the AIR app descriptor didn’t change except for the version number between beta 3 and 1.0.  I was able to simply re-compile my AIR apps to get them going.  I did have one minor freakout incident when my Loader code wouldn’t load a swf file.  It gave me an error saying that Loader couldn’t load executable code.  My initial reaction was, “OH NO!  Adobe took away that feature!  #%$&*!!”  After perusing the documentation for awhile, I realized that they had just made the system a bit more secure in that they check to make sure you know what the heck you’re doing before allowing you to execute random code in your app.  The change Adobe made was to the LoaderContext class.  They added the property allowLoadBytesCodeExecution which defaulted to false.  A quick change to my code and all was well with the world again.  Very nice job Adobe.  I’m impressed.

Post to Twitter

Posted by Andrew, filed under Flexbuilder. Date: February 25, 2008, 9:29 pm | No Comments »

I just saw on the flexcoders yahoo group that FlexBuilder 3 went live. I just bought my upgrade and will try to update all my code for the presentation Wednesday.

Post to Twitter

Posted by Andrew, filed under Flexbuilder. Date: February 25, 2008, 8:05 am | No Comments »

25  Feb
360 Flex Atlanta

Well, I’m here at 360 Flex in Atlanta that’s about to kick off this morning. It officially kicked off last night at the party, but the meat and potatoes starts today. After talking to quite a few of the other presenters, it looks like I have to start a blog. I couldn’t sleep, so here I am at 5:50am writing my first blog entry.

I own my own company called Swift Mako Software. Don’t bother clicking the link. I haven’t had time to set up a real website. It’s just a logo draft. I primarily consult for Simplified Logic, Inc., but also write some of my own code in my spare time.

My presentation is on Wednesday right after lunch on a software licensing product called Nitro-LM. It’s a first of its kind licensing tool that I developed a Flex/AIR client for. It’s been around for about 3 years in the Java/.NET/Eclipse circles, but this is the release of the interface for Flex. It’s got some really neat features and stuff, but I’ll save that for a future post.

The Omni hotel pretty much rocks. Here is a shot of the view of olympic park from my room.

360FlexAtlanta

Post to Twitter

Posted by Andrew, filed under 360 Flex. Date: February 25, 2008, 6:04 am | No Comments »