It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Flash Forum

AS3 External Interface - JS > Flash not working

Moderator: Phate

AS3 External Interface - JS > Flash not working

Postby oddball25 on Fri Aug 20, 2010 9:47 am

Hey

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:
Code: Select all
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:
Code: Select all
<!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">
<head>
<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;   
   getFlashMovie("UploadStart").sendTextToFlash(text);     
}   
function getTextFromFlash(str) {   
   document.htmlForm.receivedField.value = "From Flash: " + str;   
   return str + " received"; 
}
</script>

</head>

<body>
<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="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="Upload_Start.swf" width="964" height="510" id="UploadStart">
    <!--<![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>

<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"/>
</form>
</body>
</html>


Many thanks

John
oddball25
 
Posts: 6
Joined: Tue Dec 15, 2009 9:43 pm

Who is online

Users browsing this forum: No registered users and 0 guests