calling a Flash ExternalInterface with JavaScript

自古美人都是妖i 提交于 2019-11-29 17:05:26

Check out ExternalInterface.marshallExceptions. It should allow you to see more details about the error.

Kinda tricky to help you solve something that 'worked once'. But using ExternalInterface is pretty straightforward -- here's what I do:

in AS3: something like

...
if (ExternalInterface.available) ExternalInterface.addCallback("search", jsSearch);
...
private function jsSearch(term:String):void 
{
    new Search(data);
}

in JS: something like

...
var term = $('input#search').val();
$("#swfobject").get(0).search(term);
....
  • Make sure the javascript and the SWF are on the same domains otherwise use a crossdomain.xml
  • Make sure you have added the allowScriptAccess parameter to the flash embed
  • If you run it locally you may (but don't think it will change anything) add the location to flash players trusted ones (in the security panel).

in your as

import flash.external.*;
ExternalInterface.call("return_me_some_value()");

and in your html

<script>
var super_var = 'something';

function return_me_some_value() {
  return super_var;
}
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!