I will here collect a series of links of useful information on the interaction between flash and JavaScript, Until I have evaluated all relevant infos, to write a good summary on common practices.

  • SWFObject has grown up! version 2.0
    • static
    • dynamic
  • The famous SWFObject to easily embed flash content in html, that was previously hosted on deconcept.com has now moved to google.code basically there are 2 ways to embed your swf into your HTML site:

    Following is a basic code sample for the integration using swf object, including parameters, flashvars and attributes. (for many external interface interactions, you will need to give your swf an ID and a name)
    here the javascipt to embed, in this case for a fullBrowser embed of the swf:

    
    
    JavaScript:
    1. <script src="http://flashcrobat.noesi.co.uk/wp-admin/js/swfobject.js" type="text/javascript"><!--mce:0--></script>
    2. <script type="text/javascript"><!--mce:1--></script>
    3. <!-- later in the html page comes the div tag where you want your swf to be embedded where you can put in your alternative text, in case someone has javascript disabled, or no flash plugin installed.-->
    4. <div id="mainSwfDiv">
    5. You need Javascript activated and the flash player plugin installed to be able to view this content.
    6. The newest Flash Player can be downloaded here:
    7.  
    8. <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" /></a></div>

    Attention!!:
    giving the id or the name identical name to the swf file causes javascript errors on IE!! took me ages to find the reason for these. So just call your id and name differently than your swf is called.

  • Passing variable from JavaScript To AS3
  • A brief and basic recollection about passing vars from JS to AS3. found on: metah.ch

    <updated 04.08.2008>

    After having passed on variables inside of the swfObject script in my HTML/PHP page:

    Actionscript:
    1. //in the HTML:
    2. var flashvars = {var1:"sampleImg.jpg", var2:"my caption here"};
    3. // If you want to retrieve these vars later within your flash App:
    4. var myImagePath:String = this.loaderInfo.parameters.var1;
    5.  
    6. //to  trace all the variables (names and values) passed to the Flash Player:
    7. for ( var theName:String in this.loaderInfo.parameters ) {
    8. var theValue:String = this.loaderInfo.parameters [theName];
    9. trace("from JS :"+ theName+" "+theValue);
    10. }

  • external interface approach
  • this seems to be till now the best and easiest reference I found on smooth communicatin between Javascript and the swf in both directions. unfortunatley this only seems to work in AS2. The old fscommand now has been replaced with the externalInterface class. more to read in the Adobe.liveDocs. found on: http://flexion.wordpress.com/ source files: onBoxNet

  • AS3 Script Injection
  • Complete and unmodified JavaScript and/or VBScript functions, class objects and applications are stored inside AS3 files using XML, and are then parsed, sent to the browser, and executed. This is an ideal solution for Flash/Flex developers who need JavaScript to interact with the user's browser, but might not have full access to the webpage or server that their SWF application is actually hosted on. Flash Ads, YouTube-style video players, and games that may be hosted across multiple (and possibly unforeseen) webpages are the first things that come to mind. on: actionscript.org

  • Local Connection Actionscript - Communicate between seperate Flash files
  • Communication between two seperate flash files placed on the same page (or even running simultaneously on one machine) is a nice way to spread a project out. You can send variable, call functions, pretty much do anything in one swf from another. found on: blog.circlecube.com

  • Flash and Google analytics
  • This also fits in this cathegory, as most functionalities are handled by Javascript. I will update this entry after have=ing implemented the code on my current Project. found on: flashenabledblog.com