How to return reference to a function in ActionScript to JavaScript?
If I want to return a reference to an arbitrary function in ActionScript to JavaScript, what should I have to do?
For example, I can make an object with some method functions.
function maker()
{
const o = {};
o.a = function() {};
o.b = function() 开发者_如何转开发{};
return o;
}
I can do same thing in both of JavaScript and ActionScript. But If I send the object made in ActionScript to JavaScript via ExternalInterface
, it will be just an empty object. It's members disappears. How can I return those reference to functions?
Unfortunately, you can't.
The best thing to do is to store your function in a dictionary and pass the key, as a string, out through the external interface. Your JavaScript code can then invoke a dispatcher function with the key, to cause your AS code to call the right function.
精彩评论