We Recommend

HTML: The Definitive Guide HTML: The Definitive Guide
They teach you that learning HTML is like learning any other language and that reading a book of rules can only take you so far. Readers begin writing what may be their first Web page just two pages into the book's second chapter. From there on, they provide a wide range of HTML coding to allow readers to learn from good examples. The book includes a handy "cheat sheet" of HTML codes for quick reference.


Posted By

chrisaiv on 02/15/08


Tagged

javascript as3


Versions (?)


Who likes this?

5 people have marked this snippet as a favorite

Wiederkehr
SpinZ
Minras
pixeldata
joomla


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. </script>
  37. <!-- Send Text to Flash -->
  38. </head>
  39. <body onload="javascript:collectText(document.getElementById('welcome').innerHTML);">
  40. <p id="welcome">Ut urna lorem, sodales in, iaculis, vel heicula eu, magna. Donec ultricies toror t</p>
  41. <!-- Media Player starts -->
  42. <div id="media_player">
  43. <a href="http://www.adobe.com/go/getflash/" target="_blank"> Please Upgrade to Flash 9.0</a>
  44. </div>
  45. <script type="text/javascript">
  46. // <![CDATA[
  47. var so = new SWFObject("FLASHMOVIE.swf", "NAME_OF_FLASH_BLOCK", "700", "370", "9.0", "#ffffff");
  48. so.write("media_player");
  49. // ]]>
  50. </script>
  51. <!-- Media Player ends -->
  52. </body>
  53. </html>

Report this snippet 

You need to login to post a comment.