$( "#some_element" ).click(function() {
document.getElementById('openfl-content').my_function_1(); // this one works fine
$("#openfl-content").my_function_1(); // this one doesn’t work
});
Does anyone have any idea why externalinterface doesn’t work in cooperation with external js library?
I hope some of you is more familiar with js libraries.
Thanks for your idea ‘singmajesty’. I tested it and unfortunately it wasn’t a timing issue.
But the fact that nobody can see any problem in the code, pointed me in the right direction - the problem resides in jQuery language itself. It turned out that jQuery just needs some additional trick in order to work with externalInterface.
So here is my solution:
Instead of this:
$("#openfl-content").my_function_1();
// error: “$(…).my_function_1 is not a function”
It should be this:
$("#openfl-content")[0].my_function_1();
or this:
$("#openfl-content").get(0).my_function_1();
It is also clever to put the whole code inside “document ready” function (although it is not the essence of the matter):
$(document).ready(function() { // wait for DOM to be ready