AS3: Use HTML and JavaScript to send Text to Flash
This is the first of two ways to send Text to Flash using HTML and JavaScript. To follow my example, you must download and link to [SWFObject](http://blog.deconcept.com/swfobject/).
<!--
/*******************************
This Code Goes inside your FLA
*******************************/
import flash.external.ExternalInterface;
import flash.events.Event;
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
function getTextFromJavaScript(str:String):void {
textTxt.appendText(str);
}
var textTxt:TextField = new TextField();
textTxt.x = 0;
textTxt.y = 0;
addChild(textTxt);
-->
<!--
/*******************************
THis Lives in your HTML FILE
*******************************/
-->
<html>
<head>
<!-- Flash swfObject v1.5 -->
<script type="text/javascript" src="./js/swfobject.js"></script>
<!-- Flash swfObject v1.5 -->
<!-- Send Text to Flash -->
<script language="JavaScript">
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
function collectText(string) {
var text = string;
getFlashMovie("NAME_OF_FLASH_BLOCK").sendTextToFlash(text);
}
</script>
<!-- Send Text to Flash -->
</head>
<body onload="javascript:collectText(document.getElementById('welcome').innerHTML);">
<p id="welcome">Ut urna lorem, sodales in, iaculis, vel heicula eu, magna. Donec ultricies toror t</p>
<!-- Media Player starts -->
<div id="media_player">
<a href="http://www.adobe.com/go/getflash/" target="_blank"> Please Upgrade to Flash 9.0</a>
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("FLASHMOVIE.swf", "NAME_OF_FLASH_BLOCK", "700", "370", "9.0", "#ffffff");
so.write("media_player");
// ]]>
</script>
<!-- Media Player ends -->
</body>
</html>