dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Using externalinterface without embed tags

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    8

    Using externalinterface without embed tags

    I'm trying to keep compliant with strict XHTML 1.0, so I choose not to use the embed tags, but I run into trouble getting the externalinterface to work with Firefox, Google Chrome, and Safari.

    This is the script I used in the header

    Code:
    <script type="text/javascript">  
    <!--
    	function getFlashMovie(movieName) {  
      if (window.document[movieName]) 
      {
        return window.document[movieName];
      }
      if (navigator.appName.indexOf("Microsoft Internet")==-1)
      {
        if (document.embeds && document.embeds[movieName])
         return document.embeds[movieName]; 
      }
      else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
      {
        return document.getElementById(movieName);
      }
    
    }
    
    function formSend() {   
    var text = document.htmlForm.sendField.value;   
    getFlashMovie("player").sendTextToFlash(text);     }    
    --></script>
    while this is what my body has

    Code:
    <p>
      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="550" height="400" id="player">
        <param name="movie" value="ExternalInterfaceExample.swf" />
        <param name="quality" value="high" />
        <param name="wmode" value="opaque" />
        <param name="swfversion" value="6.0.65.0" />
        <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
        <param name="expressinstall" value="Scripts/expressInstall.swf" />
        <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
        <!--[if !IE]>-->
        <object type="application/x-shockwave-flash" data="ExternalInterfaceExample.swf" width="550" height="400">
          <!--<![endif]-->
          <param name="quality" value="high" />
          <param name="wmode" value="opaque" />
          <param name="swfversion" value="6.0.65.0" />
          <param name="expressinstall" value="Scripts/expressInstall.swf" />
          <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
          <div>
            <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
            <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
          </div>
          <!--[if !IE]>-->
        </object>
        <!--<![endif]-->
      </object>
    
    </p>
    <form name="htmlForm" method="post" action="javascript:formSend();">  Sending to ActionScript:  <input type="text" name="sendField" value="" />  <input type="submit" value="Send" /></form>
    Are the embed tags necessary in order for these browsers to use the externalinterface or is their another way?

  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    8

    Unhappy

    Ok so I am able to get it to work without the embed tags by writing my code like this:

    For the header
    Code:
    <script type="text/javascript">  
    <!--
    	function getFlashMovie(movieName) {  
      if (window.document[movieName]) 
      {
    	return window.document[movieName];
      }
      if (navigator.appName.indexOf("Microsoft Internet")!=-1)
      {
        return document.getElementById[movieName];
      }
    
    }
    
    function formSend() {   
    var text = document.htmlForm.sendField.value;   
    getFlashMovie("player").sendTextToFlash(text);     }    
    -->
    </script>
    For the body
    Code:
    <p>
    <object type="application/x-shockwave-flash" data="ExternalInterfaceExample.swf" width="550" height="400" id="player">
    	  <param name="movie" value="ExternalInterfaceExample.swf" />
          <param name="quality" value="high" />
          <param name="wmode" value="opaque" />
          <param name="swfversion" value="6.0.65.0" />
        </object>
    </p>
    <form name="htmlForm" method="post" action="javascript:formSend();">  Sending to ActionScript:  <input type="text" name="sendField" value="" />  <input type="submit" value="Send" /></form>
    However, as soon as you place text in the object, it stops functioning in Safari, Opera, and Chrome. Any ideas on how to get around this problem?

  3. #3
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    swfObject

    Learn it, love it, use it.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1
    Hello demx

    I have solved this.

    I was having the same problem and I have narrowed it down to something that might a serious bug in webkit based browsers (safari and chrome as far as I know)

    Here is the facts.

    1. You are using safari or chrome.

    2. You are using <object> tag that has an id to display a Shockwave Flash content.

    3. You may of may not have some <param> tag. That's fine.

    4. You wish to be a good guy that respect the W3C specification about accessibility and want to provide an alternate content for situations when Flash is not available. Good boy. That can be done by simply placing whatever content you want in the body of the <object> tag. Try a Google search on how to use an <obect> tag if you need more information on that.

    5. After adding the alternate content in the body that, you notice that it is no longer possible to communicate with the flash movie using ExternalInterface. Tough one, hey. In fact, it would seem like that the object's reference can no longer be retrieved the usual way.

    By the way, I had also modified the thisMovie() JavaScript function that is offered by Adobe to end up having something similar to your script (see below)

    Code:
    <script type="text/javascript">  
    <!--
    	function getFlashMovie(movieName) {  
      if (window.document[movieName]) 
      {
        return window.document[movieName];
      }
      if (navigator.appName.indexOf("Microsoft Internet")==-1)
      {
        if (document.embeds && document.embeds[movieName])
         return document.embeds[movieName]; 
      }
      else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
      {
        return document.getElementById(movieName);
      }
    
    }
    
    function formSend() {   
    var text = document.htmlForm.sendField.value;   
    getFlashMovie("player").sendTextToFlash(text);     }    
    --></script>
    The solution:

    Use document.all["player"] where moviename is the id that you gave to your Flash object. On Safari and Chrome, that will also you to retrieve the correct reference to the Flash object.

    The following with work for Chrome and Safari

    Code:
    function formSend() {   
      var text = document.htmlForm.sendField.value;   
      document.all["player"].sendTextToFlash(text);
    }
    So it is now up to you to add that to your getFlashMovie() function in a way that doesn't break the code.

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center