views:

60

answers:

2

Can I use ExternalInterface to call a namespaced JavaScript function?

//JavaScript
foo.bar = function(baz) {}

// AS3
import flash.external.ExternalInterface;
ExternalInterface.call('foo.bar', baz);
+1  A: 

Yes. Yes you can.

Cory Petosky
The question was purely theoretical, so in the way that I called it above is correctly for calling a namespaced function?
Kyle Hayes
+1  A: 

The documentation of ExternalInterface.call is a little misleading. it states the first parameter must be a function name, which is not the whole truth. it can be any string that can be evaluated as a proprer JS expression. In fact

ExternalInterface.call(func, param_1, ... , param_n);

is equivalent to

eval(func)(param_1, ... , param_n);

so you may just as well do the following

ExternalInterface.call("function (foo) { alert(foo); return true; }","test");

this technique is sometimes used for Flash JS injection. hope this clarifies things ... ;)

greetz

back2dos

back2dos
Ah yes, this does clear it up. Thanks.
Kyle Hayes