0 Replies Latest reply on Jan 12, 2007 7:42 PM by buiduyhien1234

    Problem of Ajax for Flash in IE

    buiduyhien1234
      Currently I'm doing a project that requires to deploy ajax with a Flash object. I use the fscommand for Flash to communicate with javascript in order to do the Ajax.

      I create a flash file name ask.fla. In the file I make a button and add the script for it like this:
      on(press)
      {
      fscommand ("send_var", 1);
      }
      I have read in the manual of Flash how to make flash communicate with javascript, and I have configure the publish setting of HTML file to run "Flash with FSCommand" .
      I have another 2 files namely: ask.php and ask_get.php.
      The content of the ask.php file is:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns=" http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>ask</title>
      </head>
      <body bgcolor="#ffffff" onload="makeRequest('ask_get.php','?test=10');">
      <script language="JavaScript">
      <!--
      var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
      // Handle all the FSCommand messages in a Flash movie.
      function ask_DoFSCommand(command, args) {
      var askObj = isInternetExplorer ? document.all.ask : document.ask;
      alert("HELLO");
      }
      var http_request = false;
      function makeRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/html');
      }
      } else if (window.ActiveXObject) { // IE
      try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
      try {
      http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
      }
      }
      if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
      }
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url + parameters, true);
      http_request.send(null);
      }

      function alertContents() {
      if (http_request.readyState == 4) {
      if (http_request.status == 200) {

      result = http_request.responseText;
      document.getElementById('myspan').innerHTML = result ;
      } else {
      alert('There was a problem with the request.');
      }
      }
      }
      if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
      document.write('<script language=\"VBScript\"\>\n');
      document.write('On Error Resume Next\n');
      document.write('Sub ask_FSCommand(ByVal command, ByVal args)\n');
      document.write(' Call ask_DoFSCommand(command, args)\n');
      document.write('End Sub\n');
      document.write('</script\>\n');
      }
      //-->
      </script>
      <!--url's used in the movie-->
      <!--text used in the movie-->
      <div name="myspan" id="myspan"></div>

      </body>
      </html>
      The content of the ask_get.php is:
      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="ask" width="462" height="410" align="middle">
      <param name="allowScriptAccess" value="sameDomain" />
      <param name="movie" value="ask.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="ask.swf" quality="high" bgcolor="#ffffff" width="462" height="410" swLiveConnect=true id="ask" name="ask" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage=" http://www.macromedia.com/go/getflashplayer" />
      </object>

      The purpose of the two file is that when the file ask.php is called, the code in the even <body onload> will call the makeRequest function, which replate the <div name="myspan" id="myspan"> with the code in the file ask_get.php, so that the flash object is embed indirectly in the file.(but it will be shown, and some how I use it to make the ajax for the page).
      When I run the file ask.php in my webserver in Mozilla FireFox, it run well, the flash file can call the javascript function, but when I run the file ask.php in IE, the flash file can not do anything, it can not call the javascript function.
      You can check this by running the file ask.php in both FireFox and IE in your webserver (IIS or Apache).
      If the code to embed the swf object in php file is written directly in the very php file the swf object can contact with javascript very well and correctly
      , as you can test it by running the file ask1.php in both IE and FireFox in your webserver (IIS or Apache) , when you click the button, it will show you the message "HELLO" which is call from a javascript function.
      Here is the code of the file ask1.php, which embed the flash object directly in the php file and it works well in both FireFox and IE:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns=" http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>ask</title>
      </head>
      <body bgcolor="#ffffff" onload="makeRequest('ask_get.php','?test=10');">
      <script language="JavaScript">
      <!--
      var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
      function ask_DoFSCommand(command, args) {
      var askObj = isInternetExplorer ? document.all.ask : document.ask;
      alert("HELLO");
      }
      if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
      document.write('<script language=\"VBScript\"\>\n');
      document.write('On Error Resume Next\n');
      document.write('Sub ask_FSCommand(ByVal command, ByVal args)\n');
      document.write(' Call ask_DoFSCommand(command, args)\n');
      document.write('End Sub\n');
      document.write('</script\>\n');
      }
      //-->
      </script>
      <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="ask" width="462" height="410" align="middle">
      <param name="allowScriptAccess" value="sameDomain" />
      <param name="movie" value="ask.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="ask.swf" quality="high" bgcolor="#ffffff" width="462" height="410" swLiveConnect=true id="ask" name="ask" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage=" http://www.macromedia.com/go/getflashplayer" />
      </object>
      </body>
      </html>
      The problem is when I call an object by replacing the <div id=...> with the code for the flash object from the ask_get.php file, only FireFox can call the javascript but IE does not.
      So anyone who know the reason why, please tell me. Thank you very much.