开发者

How to return reference to a function in ActionScript to JavaScript?

开发者 https://www.devze.com 2023-04-11 09:40 出处:网络
If I want to return a reference to an arbitrary function in ActionScript to JavaScript, what should I have to do?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号