calling a Flash ExternalInterface with JavaScript

后端 未结 4 476
一个人的身影
一个人的身影 2020-12-22 01:23

I\'m trying to call a function declared with ExternalInterface in a Flash swf, using JavaScript. It worked once, but all of a sudden, it stopped working.

I have a d

相关标签:
4条回答
  • 2020-12-22 01:46

    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);
    ....
    
    0 讨论(0)
  • 2020-12-22 01:48
    • 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).
    0 讨论(0)
  • 2020-12-22 02:08

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

    0 讨论(0)
  • 2020-12-22 02:09

    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>
    
    0 讨论(0)
提交回复
热议问题