Execute dynamic javascript from Flash with ExternalInterface

So I was playing around with the ExternalInterface class earlier today and wondered if I could call dynamic javascript with it, as opposed to the standard approach of calling an existing javascript function. And it appears that you can. I tried the following…

// Simple launch of the alert dialog
ExternalInterface.call("function() { alert('Testing'); }");

// Changed the height of a div
ExternalInterface.call("function() { document.getElementById('divID').style.height = '300px'; }");

// And with the jquery library included in the html head
// Call the toggle function
ExternalInterface.call("function() { $('#divID').toggle('fast'); }");

And what do you know! All of those work just fine.

Ideally you’d have a js file set up with functions for Flash to call. But I can certainly see how there might be some cases where you’d want/need to use the dynamic calls.

Feel free to download my test files for a closer look.

0 comment(s)

Track this comments via RSS 2.0 feed. Feel free to post the comment, or trackback from your web site.

Comment on this post