Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling a Flex/AS3 Callback from Javascript
    primarykey
    data
    text
    <p>I have a Javascript API, which should be usable with GWT and Flex. Using the FABridge it is really easy to call Javascript methods from AS3 and vice versa. But when I try to register a callback to an AS3 method in my Javascript API I get stuck. Here is a short code sample:</p> <pre><code>public function initApp():void { if (ExternalInterface.available) { ExternalInterface.addCallback("foobar", foobar); } } public function foobar():void { //the callback function Alert.show("Callback from API works!"); } private function btnCallbackClicked():void { ExternalInterface.call("testAPICallbackFromJS", Application.application.foobar); } </code></pre> <p>And the simple JS method:</p> <pre><code>function testAPICallbackFromGWT(callback){ $clinit_26(); //added by the GWT compiler alert('callback to be launched 3 2 1'); callback(); } </code></pre> <p>But this version does not work, because I always receive an empty function in my JS code. It seems that the FABridge is cutting the rest. Then I tried a different approach. I wrote a little JS method, which takes the name of the function and creates the callback from the JS side.</p> <pre><code>registerFlexCallback = function(registerMethod, callback, id) { /* workaround to create a callback for an AS method, which can be called by Javascript * registerMethod - Javascript method which shall be called for registration with the created callback as parameter * callback - AS method that shall be called by Javascript (available over the FABridge interface) * id - ID of the flash object (use Application.application.id in AS) */ var swf = document.getElementById(id); eval(registerMethod + "(swf." + callback + ");"); }; </code></pre> <p>This one works well with the Internet Explorer, but with no other browser. For example in Firefox I get the following error message: </p> <pre><code>NPMethod called on non-NPObject wrapped JSObject! </code></pre> <p>Can somebody tell me, what this error is about (maybe some kind of security issue)? Or does anyone have a better idea how to create callbacks for my AS3 methods which can be called by JS?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload