Flex: Loading Remote Modules Throws the following: “Error: Unable to load resource module from…”

Recently I was working on localizing a Flex project to handle multiple languages.  There are a bajilion examples on the web of ways to do this, and I found a few helpful ones.  The most helpful was this one.

Since the strings are changed by the client in a php admin console, the server was compiling these modules for each language I needed.  So, the Flex app had to load the resource modules at run time, AND they were coming from a different domain (S3 in our case).  I played with the security settings for loading a remote module as suggested by sites like this: And I was able to get my app to load the resource module from an external domain when I ran the Flex app from localhost, but when I tried to run the app locally, I kept getting this error:

“Error: Unable to load resource module from http://domainname.com/locales/en_US.swf”

I didn’t want to always debug my app from localhost, (that’s lame) so I needed a way around the Flex security restrictions.

I dug around a while looking for something to get my by, and I found people with the same error here and here. Along with one result in Russian, which I didn’t understand.  Generally the answer was to load things from localhost and that should solve your issue, but like I said didn’t want to run things from localhost.

Then a beam of light crested over the horizon, licking the hopeless feelings which had me on the verge of desisting. I asked coworker, and fellow Flexer Aaron Hardy what he recommended, and he pointed me to something he had done for loading style modules.  He said: “Try this. It might work” So I gave it a whirl, and BAM! It worked first try baby.  So here is what I had:

private function loadLocaleResource():void
{
var eventDispatcher:IEventDispatcher =
resourceManager.loadResourceModule("FULL_URL_TO_MODULE");
eventDispatcher.addEventListener(
ResourceEvent.COMPLETE, resourceCompleteHandleer);
}

and after getting the RemoteStyleMarshaller from Aaron, this is what I changed it to:

private var moduleLoader:RemoteStyleMarshaller;
//loads the module with the locale resources
private function loadLocaleResource():void
{
moduleLoader = new RemoteStyleMarshaller("FULL_URL_TO_MODULE", false);
moduleLoader.addEventListener(StyleEvent.COMPLETE, resourceCompleteHandleer);
moduleLoader.loadStyleDeclarations();
}

You can find a full explanation of what Aaron’s class does at his blog. Basically what his RemoteStyleMarshaller does is skirt around the security settings of Flash by loading in the bytes of the module.

Hopefully this post, along with Aaron’s class will help anyone running into the same issue.

NOTE:  After working through this issue with Aaron, he may post an update to his code on his site, since now it is apparent that his RemoteStyleMarshaller does more than just marshall style modules. Aaron is the hero of the day.

By: Bryce Barrand Categories: debugging / flex

3 Responses to Flex: Loading Remote Modules Throws the following: “Error: Unable to load resource module from…”

  1. sriiz says:

    HI..
    i have seen aaron’s blog for “Loading Remote Resource Module”
    i m unable to make that “code” to use”. i m new to flex so it is little hard to how exactly use the code running for u. it would be very helpful if u can share your source code which you have used for implementing it.

  2. Kishore says:

    Hi,

    I am trying to load CSS swf at runtime by using Aaron classes. but not able to load remote css swf file.can u please give me example which has complete steps please… please help me in this.

    Thanks
    J Kishore

Leave a Reply