How to expose the JavaScript interface for an embe

2019-07-11 21:20发布

问题:

JavaScript and the Flash Player can exchange data via Flash's ExternalInterface mechanism: you register ActionScript functions that you would like to be able to be called from JavaScript.

My question: How can I figure out what ActionScript functions of a Flash object are available for me to call from JavaScript (assuming they are not documented)?

Is there a programatic way to do this in JavaScript?

Thanks!

回答1:

you can't enumerate them directly (they won't be listed in a for..in loop), but you can test for each one explicitly...

var swf = document.getElementById('theID');
alert('someMethod' in swf);  // will alert true if 'someMethod' is exposed via ExternalInterface.addCallback

this might fail if called during $(document).ready or window.onload - the swiff must be 'initialized' (loaded and registered) for the exposed methods to be available at all.