3

I am struggling with flash and firefox (latest, 35.0.1) and can't find any solution. I want to call an ActionScript function with javascript, using ExternalInterface. So I wrote this simple javascript function (App is just an object to wrap my functions):

App.swfCall = function(callbackName, params) {
    var callback = $('#swf object, #swf embed')[0][callbackName];
    if(typeof(callback) === "function") {
        callback.apply(null, params); // executed but throws NPObject error...
    }
}

And Firefox throws an error:

Bad NPObject as private data!

The only help I found about this error is not relevant with my issue, as:

  • Everything is ready at this moment; actually the action is first initiated by a user action on the swf itself
  • There is no cross-domain issues (everything on the same domain)

Actually, if I do not use the Function javascript object (either with call() or apply()), everything works fine. So this is working:

App.swfCall = function(callbackName, data) {
    var swf = $('#swf object, #swf embed')[0];
    if(typeof(swf[callbackName]) === "function") {
        swf[callbackName](data);
    }
};

Anyway there are many problems with this:

  • I can just pass a single argument to the function
  • ...And I have to check if the parameter is the "data" parameter is not null
  • I cannot pass null parameters beacause of that (not the biggest issue)

So all I need is to be able to pass parameters to the swf (0, one or more!) And I'd really like to understand what is happening, too.

I said there is no cross-domain issues, actually it is an iframe within facebook. But obviously everything is inside it and on the same domain, so it shouldn't be a problem.. should it?

Thank you!

Vivien Ln
  • 171
  • 7
  • try to read this http://stackoverflow.com/questions/1038668/cross-domain-externalinterface-error-calling-method-on-npobject – Dmitry Malugin Feb 25 '15 at 07:01
  • Thanks, but my problem shouldnt be related to cross-domain issue, since everything is on the same domain. Anyway I'll try to set allowscriptaccess to "always", though since it's set to "sameDomain" by default, which should be sufficient. So I am not sure this is going to solve anything.. – Vivien Ln Feb 25 '15 at 16:57
  • allowscriptaccess should be true it doesn't related to crossdomain policy, read documentation – Dmitry Malugin Feb 26 '15 at 06:43
  • I explicitely set allowscriptaccess to "always"; and as expected I still have the error. In your link System.security.allowDomain is also mentioned, though once again the original issue is with two files on 2 domains. Maybe I am misunderstanding something, but I still have this "Bad NPObject" error. And strangely it works just by not using a Function object... I dont get why. Anyway, thank you for your help – Vivien Ln Feb 26 '15 at 14:26

1 Answers1

1

If you want to put you parameters as an array to your function you can try it with the new in ECMA6 defined Spread Operator:

App.swfCall = function(callbackName, data) {
  var swf = $('#swf object, #swf embed')[0];
  if(typeof(swf[callbackName]) === "function") {
    swf[callbackName](....data);
  }
};

A description of the operator can be found here: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/Spread_operator

Ksul
  • 11
  • 2