A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS3 External Interface - JS > Flash not working

  1. #1
    Junior Member
    Join Date
    Jan 2010

    AS3 External Interface - JS > Flash not working


    Having a problem trying to get the external interface working with as3.

    My flash file has 2 input text boxes with instances of 'received_ti' and 'sending_ti' and a button with instance of 'send_button'.

    My html code has a simple form with 'sendField' and 'receivedField' inputs and a submit with a value of 'Send'.

    At the moment i can get the flash file to send text into the html 'receivedField' input but cannot send text from html into the flash file's 'received_ti' text box.

    Can anyone help me out with this? I am really struggling... My full code is below:

    Flash AS3:
        import flash.external.ExternalInterface;
        import flash.events.Event;
        ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
        send_button.addEventListener("click", clickSend);
        function getTextFromJavaScript(str:String):void { 
           received_ti.text = "From JavaScript: " + str;
        function clickSend(event:Event):void { 
           var jsArgument:String = sending_ti.text; 
           var result:Object = ExternalInterface.call("getTextFromFlash", jsArgument); 
           received_ti.text = "Returned: " + result;

    HTML & Javascript:
        <!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">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Upload Start</title>
        <script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
        <script type="text/javascript"> 
        function getFlashMovie(movieName) {   
           var isIE = navigator.appName.indexOf("Microsoft") != -1;   
           return (isIE) ? window[movieName] : document[movieName]; 
        function formSend() {   
           var text = document.htmlForm.sendField.value;   
        function getTextFromFlash(str) {   
           document.htmlForm.receivedField.value = "From Flash: " + str;   
           return str + " received"; 
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="964" height="510" id="UploadStart">
          <param name="movie" value="Upload_Start.swf" />
          <param name="quality" value="high" />
          <param name="wmode" value="opaque" />
          <param name="swfversion" value="" />
          <!-- 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="Upload_Start.swf" width="964" height="510" id="UploadStart">
            <param name="quality" value="high" />
            <param name="wmode" value="opaque" />
            <param name="swfversion" value="" />
            <param name="expressinstall" value="Scripts/expressInstall.swf" />
            <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
              <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>
            <!--[if !IE]>-->
        <form name="htmlForm" method="POST" action="javascript:formSend();"> 
        Sending to ActionScript:<br /> 
        <input type="text" name="sendField" value="" /><br /> 
        <input type="submit" value="Send" /><br />  <br /> 
        Received from ActionScript:<br /> 
        <input type="text" name="receivedField"/>
    Many thanks


  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    To be safe, give your <object> tags and name and id of the same value
    <object id="UploadStart" name="UploadStart"/>

    I'm not sure why you have a potential nested object tag. You should really be using swfobject to handle the .swf embed.

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