AIR, Flex, LocalConnection and the mystery StatusEvent

Posted on July 21, 2007 | 8 comments

I have had some code working for a while that stopped working with the latest build of Flex Builder 3 I installed. The code was an AIR application that received messages from arbitrary Flex applications using LocalConnection. The problem with LocalConnection and AIR is the inherent security issues that arise. AIR is on the desktop with no domain sandbox and the Flex apps usually are coming from application with domains. So typically I set the allowDomain() method on the LocalConnection instance, and then it works.

I didn’t change any of my code and I was getting a mystery “Error #2044: Unhandled statusEvent:. level=error, code=”. After digging around for a while I noticed the Security class in the AIR framework and that it also had an allowDomain method. I added Security.allowDomain(“*”); to my code and it started working again.

LocalConnection with AIR and Flex on the Mac OS X seems to be a bit weird at times. So I am not sure it was a Mac, AIR, or Flex thing. But if you come across some strange #2044 with no explanation make sure your Flash Player/AIR security sandboxes are correct by setting allowDomain where ever needed (Security, LocalConnection instance, etc…).

  • Lanny

    I am having a similar problem, however the Security.allowDomain(“*”) throws a SecurityError of its own:

    SecurityError: Error #3207: Application-sandbox content cannot access this feature.
    at flash.system::Security$/allowDomain()

    Any thoughts?

  • http://www.renaun.com Renaun Erickson

    I have since dropped the Security.allowDomain(“*”), and it does give you that error.

    This is what i have now:

    connection = new LocalConnection();
    connection.allowDomain(“*”);
    connection.client = this;
    connection.connect(“_myconnect”);

    It works fine, try with out the Security.allowDomain() if that doesn’t work share an example NetConnection code you are trying.

  • http://timostamm.de Timo Stamm

    I just ran into this problem too, but I don’t see any connection to the security settings. The problem is not consistent. It only showed in release builds for me.

    Got rid of the problem by reordering the code a little bit and doing a rebuild. It’s not the first time this has worked. The compiler has some issues it seems.

  • Mauricio Reyno

    My problem is a little different, but maybe anyone can help me.
    I have an swf1 who loads another swf2 into (both flex made).
    When I send something to the class .as of swf2 seems to dont have connection with none of both swf´s. It seems to be on another level but dont see a solution for it. Seems the .as class dont have connection with the localconnection or any other component on swf2.

    Any ideas?

    tnx

  • Shanimal

    Seeing in AS3 app for FB, having crossdomain issue onfbjs-bridge. Note that this works in FireFox (FAIL only in IE)

  • http://www.funky-monkey.nl/blog/ Sidney de Koning

    Hi,

    I dont know if you already solved this problem correctly, but there is a sollution.
    This error probably always happends if you have not yet started your application but already start sending messages to it right?
    It also sounds like you are building a logger of some sort. (if not, you can use the same approach)
    What you can do it this. Create a private var called _canSend and _hasListeners (default them both to false), create getters and setters for _canSend, then in the function you use to send over the localconnection, check if(!_hasListeners) and you add the listener for the StatusEvent. In the event handler just trace out something. Like this:


    private static var _hasListeners:Boolean = false;
    private static var _isLogging:Boolean = true;

    public function get isLogging():Boolean {
    return _isLogging;
    }
    public function set isLogging(value:Boolean):void {
    _isLogging = value;
    }

    and then the actual sending like so;

    public static function send(pInput:*, level:String):void {

    if(!_hasListeners) {
    LOCAL_CONNECTION.addEventListener(StatusEvent.STATUS, onStatusHandler);
    }
    if(_isLogging) {
    LOCAL_CONNECTION.send( LOCAL_CONNECTION_NAME , OUTPUT_METHOD , pInput.toString( ) , level );
    }
    }

    Because now you catch the event and you dont have to have you application open first before you start sending.
    I hope this works for you,

    Happy coding :)

    Sid

  • Pingback: Paul Gregoire’s Blog » Blog Archive » The dreaded 2044 error

  • http://gregoire.org Paul Gregoire

    Renaun, I have expanded upon this issue because it happened to me under different conditions.
    http://gregoire.org/2009/01/23/the-dreaded-2044-error/

  • http://keith-hair.net Keith H

    Thanks the allowDomain method was the solution to my “AIR security gotcha” when dealing with a LocalConnection.