Error 2112 in Flex Using EarthBrowser’s Mac Middle Mouse Fix

We’re using the EarthBrowser Mac Mouse Wheel fix in our current Flex project. I was noticing some sporadic “SecurityError: Error #2112: Provided parameter LoaderContext.ApplicationDomain is from a disallowed domain.” pop up, but only when scrolling our TileList via the middle mouse. If you used the mouse on the scrollbar, it worked fine.

I found the cause of the problem was when the JavaScript called Flash Player via ExternalInterface, eventually the loader.load call in the Flex Image control would throw an exception. Since the Flex 3.3 SDK< doesn’t wrap the load with a try/catch, there is no way to catch this error.  If you’ve ever attempted to debug ApplicationDomain errors in ActionScript, you know it’s a time sink… and hard.  So, I never really found out the problem, but did find a solution.

The fix is to delay the MouseEvent.MOUSE_WHEEL dispatched by 1 frame using UIComponent’s built-in callLater function.  I wish I had time to find out the true cause, but at this point, all I have is conjectures.  My guess is that the call stack that JavaScript is initiating via ExternalInterface is sequestered in memory, perhaps in a temporary ApplicationDomain.  This then is perhaps why the ApplicationDomain.currentDomain differs from the usual one.  Since there is a lot of security around MouseEvents now (triggering File downloads/uploads, initiating full screen playback, etc.) it makes sense.

Anyway, in my testing, my fix seems to work pretty good; haven’t gotten an error yet.  We’ll be testing the updated code all week, so if I find any issues, I’ll update this post.  Here’s the code I modified in MacMouseWheelHandler.as on line 72:

static private function _externalMouseEvent(delta:Number):void
{
        // [jwarden 1.25.2010] Originally, it'd just dispatch the event immediately.
        // However, we were getting image loading errors when you scrolled on some tile pages.
        // I believe this is because when JavaScript executes, the stack is in a protected
        // memory space, and the ApplicationDomain.currentDomain utilized by the Image control
        // is different than normal.  This causes a 2112 error, and since the Flex 3.3
        // image control doesn't wrap loader.load with a try/catch, the exception blows
        // things up.  If I wait a frame via callLater, the problem goes away.
        // Still trying to find out why, but for now, she works.
        if(_currItem && _clonedEvent)
        {
                var mouseEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false,
                                                              _clonedEvent.localX, _clonedEvent.localY, _clonedEvent.relatedObject,
                                                              _clonedEvent.ctrlKey, _clonedEvent.altKey, _clonedEvent.shiftKey, _clonedEvent.buttonDown,
                                                              int(delta));

                if(_currItem is UIComponent)
                {

                        UIComponent(_currItem).callLater(_currItem.dispatchEvent, [mouseEvent]);
                }
                else
                {
                        _currItem.dispatchEvent(mouseEvent);
                }
        }
}

If you’re not using Flex, and just pure AS3, you might try providing a way for your components to wait a frame utilizing Event.ENTER_FRAME.

8 Replies to “Error 2112 in Flex Using EarthBrowser’s Mac Middle Mouse Fix”

  1. Bad news: This doesn’t fix it. Additionally, using SWFWheel doesn’t fix it either; both have the same problem.

    Good news: I CANNOT duplicate this error in 10.0.x, just 10.1 beta.

  2. I’m getting this error with the 10.1 beta as well when loading images. It’s on photo gallery that dynamically loads images. The first and second images chosen by the user show up fine; the third throws the error. They’re all from the same source. This has to be a bug in the player.

    Additionally, I’m getting really bizarre errors trying to recompile the source for this since installing the beta player. I’m using an internal class which extends Loader. It always compiled fine before. For some reason now it’s throwing an error on the declaration of a constant in the class. Very weird.

  3. I just got this as well on Windows once moving to 10.1. Our datagrids now dispatch this runtime error if you try to scroll them via the mouse wheel. I’m going to check the Adobe Jira to see if they have this filed anywhere.

  4. Hey Jesse, did you find an answer to this? I’ve got two versions of this 2112 bug on pretty high profile sites, that only show up in the 10.1 beta. My dyslexic wastedness caused me to post this under a bug 1221 issue on the adobe forum for the beta, which is still floating around the top with no response from the adobe heads. Heard this has cropped up with Hulu as well. I hope you’ll post it up here if you figure it out…

  5. Sweet! Thanks all for explaining this. I was using the older 10.1 beta and got the exception just by scrolling a Spark List (tile layout) and an Image item renderer.

    I removed the 10.1 beta and problem went away, grabbing the latest 10.1 beta right……. now!

Comments are closed.