Posted By

chrisaiv on 02/15/08


Tagged

javascript as3


Versions (?)

Who likes this?

7 people have marked this snippet as a favorite

Wiederkehr
SpinZ
Minras
pixeldata
joomla
ssolen
tspitzr


AS3: Use HTML and JavaScript to send Text to Flash


 / Published in: HTML
 

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/

  1. <!--
  2. /*******************************
  3. This Code Goes inside your FLA
  4. *******************************/
  5. import flash.external.ExternalInterface;
  6. import flash.events.Event;
  7.  
  8. ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
  9. function getTextFromJavaScript(str:String):void {
  10. textTxt.appendText(str);
  11. }
  12.  
  13. var textTxt:TextField = new TextField();
  14. textTxt.x = 0;
  15. textTxt.y = 0;
  16. addChild(textTxt);
  17. -->
  18. <!--
  19. /*******************************
  20. THis Lives in your HTML FILE
  21. *******************************/
  22. -->
  23. <!-- Flash swfObject v1.5 -->
  24. <script type="text/javascript" src="./js/swfobject.js"></script>
  25. <!-- Flash swfObject v1.5 -->
  26. <!-- Send Text to Flash -->
  27. <script language="JavaScript">
  28. function getFlashMovie(movieName) {
  29. var isIE = navigator.appName.indexOf("Microsoft") != -1;
  30. return (isIE) ? window[movieName] : document[movieName];
  31. }
  32. function collectText(string) {
  33. var text = string;
  34. getFlashMovie("NAME_OF_FLASH_BLOCK").sendTextToFlash(text);
  35. }
  36. <!-- Send Text to Flash -->
  37. </head>
  38. <body onload="javascript:collectText(document.getElementById('welcome').innerHTML);">
  39. <p id="welcome">Ut urna lorem, sodales in, iaculis, vel heicula eu, magna. Donec ultricies toror t</p>
  40. <!-- Media Player starts -->
  41. <div id="media_player">
  42. <a href="http://www.adobe.com/go/getflash/" target="_blank"> Please Upgrade to Flash 9.0</a>
  43. </div>
  44. <script type="text/javascript">
  45. // <![CDATA[
  46. var so = new SWFObject("FLASHMOVIE.swf", "NAME_OF_FLASH_BLOCK", "700", "370", "9.0", "#ffffff");
  47. so.write("media_player");
  48. // ]]>
  49. <!-- Media Player ends -->
  50. </body>
  51. </html>

Report this snippet  

You need to login to post a comment.