0

i am working with JS and AS3 to get default mic. below is my html code

js on head

    $(document).ready(function(){
     $("#setupMic").click(function() {
      try{
       document.getElementById('test').setupMic();
      } catch(err) {
       console.log(err.message);
      } 
     });
    });
    
js after div flashContent
    var callback = function(e){ if(e.success) console.log("Loading Success"); else console.log("Loading Failed");};
    var flashvars = {};
    var params = {allowscriptaccess:"always"}; 
    var attributes = {};
    attributes.id = "test";
    swfobject.embedSWF("test.swf", "flashContent", "220", "140", "10", false, flashvars, params, attributes, callback);
    
my AS3 code is
    import flash.system.Security;
    import flash.external.ExternalInterface;
    var mic:Microphone;
    Security.allowDomain('*');
    ExternalInterface.addCallback("setupMic", setupMic);
    function setupMic():void {
     mic = Microphone.getMicrophone();
     mic.setLoopBack(true);
    }
    
the html is working perfectly in firefox. but not with my chrome or safari on friends mac. what am i missing. please help
abduIntegral
  • 521
  • 4
  • 7
  • 21
  • is it due to some security issue. in firefox to work at first i need to add trusted location on flash player setting manager. if i change location, it wont work in firefox too. any hind ? – abduIntegral Apr 30 '13 at 09:17

1 Answers1

0

You may have a timing issue. Flash Player takes a moment to initialize ExternalInterface. If you try and access the SWF on domready, Flash Player might not have finished initializing ExternalInterface, which means your method setupMic() might not be available yet.

I recommend querying the SWF to see if it has finished loading. There's an example on LearnSWFObject.com: http://learnswfobject.com/advanced-topics/executing-javascript-when-the-swf-has-finished-loading/

pipwerks
  • 4,440
  • 1
  • 20
  • 24
  • thank you for you reply. that don't seems the problem. i tried waiting long and then call setupMic(). No change. I checked with the finish loading example you gave and tried to call setupMic() after the alert("The SWF has finished loading!"); but don't work in chrome, in firefox it works fine – abduIntegral Apr 29 '13 at 06:23
  • is it due to some security issue. in firefox to work at first i need to add trusted location on flash player setting manager. if i change location, it wont work in firefox too. any hind ? – abduIntegral Apr 30 '13 at 09:15
  • Are you running it locally or on a server? ExternalInterface is sandboxed when run locally, you should try testing your site on a server. – pipwerks Apr 30 '13 at 19:18
  • when i tested locally it worked only in firefox. its a part of chat application. i am implementing it using node.js. if a request is made on server systems port 8000. server.js will load our client.html. swf is embedded in that one. but on testing it on server its working in no browser. in firefox too i am getting TypeError: document.getElementById(...)setupMic is not a function – abduIntegral May 01 '13 at 04:36
  • little more about above comment. what happen to swfembed if the html is loaded indirectly. some other programs read the html file data and viewed. should that create any prolem – abduIntegral May 01 '13 at 08:55