NPObject Error Using Firefox, Flash, and Javascript

The Flash security sandbox has been around for a while so you'd think we'd seen all the errors. When firefox started reporting an "error calling method on NPObject," I was surprised to find Google didn't drop the answer at my feet. No, this took a bit more exploring to figure out.

Error calling method on NPObject

When this error pops up, it's not because the function isn't there. Otherwise you'd get a message like "flashMovie.myFunc is not a function." When this happens it means the function is defined but for some reason Flash doesn't think you should be calling it.

Now with the security sandboxes this could be for a number of different reasons.

  • Local content trying to access the internet
  • Internet content trying to access local content
  • Content from one domain trying to access content from another

I'd started hosting my SWFs on a different domain so my problem was definitely the latter. Creating a crossdomain.xml policy file on both domains didn't solve the problem, either. It turns out you have to add a couple lines right inside your SWF file to allow cross-domain scripting.

import flash.system.Security;
Security.allowDomain('otherdomain.com');

That's it. Now, no matter which domain hosts the SWF, you can still communicate with it from otherdomain.com.

I just wish the error message could be a little less mysterious is all.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

About

Daniel McLaren

Daniel is a Flash and Flex developer specializing in the art of information visualization.

Latest from SketchyD

Latest Drawing from SketchyD

This is the most recent drawing from my mobile sketch blog, SketchyD.com.

Recent comments