Fire-Hox
Fire-Hox

Reputation: 563

Javascript: calling javaScript function from flash (swfObject)?

let suppose i have a object named "data" which has a callBack function named "closeItem" which does something.

So i have flash file which has a close button. on click of that i am calling this function which closes this item.

So issue is ?

If i pass this "closeItemFunction" as global function this works fine.

but if a pass this function as a "data.closeItem" this doesn;t work throwing some falsh error .

so i just wanna ask that


"does flash only call gobal scoped javascript function" ??

Upvotes: 0

Views: 1516

Answers (2)

Lars Blåsjö
Lars Blåsjö

Reputation: 6127

You can wrap the JavaScript you want to execute in an anonymous function that you declare and call from ActionScript, like this:

ExternalInterface.call("function() { data.closeItem(); }");

It may seem a bit odd that the function gets called, executed, with the above syntax, it does, but if you prefer you could make the declaration and separate call more explicit, like this:

ExternalInterface.call("(function() { data.closeItem(); })()");

Upvotes: 2

Jonatan Hedborg
Jonatan Hedborg

Reputation: 4432

Short answer (iirc); "yes".

It might be possible to get around by calling

ExternalInterface.call("eval", "data.closeItem()")

Upvotes: 1

Related Questions