Send Text from Flash to HTML Form
This Flash and HTML interactivity example demonstrate how to send text message in Text Field from Flash Movie ActionScript to JavaScript HTML Text Field on webpage.
Flash Tutorial Content:
This Flash ActionScript and HTML JavaScript interactivity tutorial shows how to call JavaScript in HTML from ActionScript in Flash.
The completed Flash Movie of this tutorial is shown as above. You may play around to see how it works.
Flash ActionScript and HTML Codes:
Flash Side:
Use ExternalInterface.call( ) method to call to JavaScript functions from ActionScript.
var result:Object = ExternalInterface.call("getTextFromFlash", jsArgument);
The code in Flash Movie will call the JavaScript getTextFromFlash () function with a parameter of jsArgument. You can pass any parameters with the function you like. In this tutorial, we pass the text in the Text Field with the function.
HTML Webpage Side:
Remember that The function must be defined in the HTML page with the same name.
Step 1:
Layout a Text Field on the HTML webpage.
<form name="htmlForm" method="POST" action="javascript:formSend();">
<input type="text" name="receivedField" size="35" value="">
</form>
Step 2:
Write the JavaScript function getTextFromFlash. The JavaScript function will be called from ActionScript function when the send button in the Flash Movie is clicked.
<script language="JavaScript">
function getTextFromFlash(str) {
document.htmlForm.receivedField.value = "From Flash: " + str;
return str + " received";
}
</script>
Download Flash Source File:
Awaiting to be released.
Remarks:
This Flash ActionScript tutorial shows how to call HTML JavaScript from Flash ActionScript.