View comments | RSS feed

Using FlashVars to load and display text

Using FlashVars is simple, but requires you to publish your SWF files along with HTML documents. You modify the generated HTML code and include the FlashVars properties in both the object and embed tags. You can then test the Flash document by viewing the modified HTML document in your web browser.

To use FlashVars to pass variables from HTML to your Flash document:

  1. Create a new Flash document and save it as flashvars.fla.
  2. Add the following ActionScript to Frame 1 of the Timeline:
    this.createTextField("my_txt", 10, 10, 10, 100, 21);
    my_txt.text = _level0.username;
    
  3. Save the Flash document and select File > Publish to generate the HTML and SWF files.

    NOTE

     

    An HTML document publishes, by default, to the same directory as your FLA file. If an HTML document does not publish, select File > Publish Settings and then select the Formats tab. Make sure that you select HTML.

  4. Open up the flashvars.html document in a text or HTML editor.
  5. In the HTML document, modify the code inside the object tag to match the following.

    The code you need to add is in boldface.

    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="flashvars" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="flashvars.swf" />
    <param name="FlashVars" value="username=Thomas" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <embed src="flashvars.swf" FlashVars="username=Thomas" quality="high" bgcolor="#ffffff" width="550" height="400" name="flashvars" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
    </object>
    
  6. Save your changes to the HTML document.
  7. Open the modified HTML in a web browser.

    The SWF file displays the name "Thomas" in the dynamically created text field on the Stage.

For information on security, see Understanding Security.


Flash CS3


Comments


No screen name said on Jul 18, 2007 at 6:41 PM :
I tried using FlashVars and loading a URL for AS2 with both CS3 and Flash 8 to no avail. They both come up as undefined on the local and when i up to a server. Why isn't this basic tutorial working for me? Im really confused since it seems so straight forward. Did I miss something?
bclover said on Oct 17, 2007 at 9:30 AM :
If you are publishing your SWF with the Active Content Fix, you also have to include the FlashVars information in the Javascript portion of the HTML code. For example:

<script>
AC_FL_RunContent(
'movie', 'flashHelper',
'width','48',
'height','1516',
'id','someID',
'FlashVars','flashguy=bclover&company=IntuitiveMedia_LLC'
);
</script>
No screen name said on Mar 5, 2008 at 5:06 AM :
Thanks bclover, that works for me. However, does anyone know why I even need the FlashVars bit at all if it only reads the javascript?

Personally I don't want to use the big ugly JavaScript, I'd rather just pass the parameter into the object /embed tags. Can I do that? If I remove all reference to JavaScript it doesn't work at all!

PS I'm a noob if you hadn't guessed already :' |
Ivan Stimac said on Mar 9, 2008 at 11:19 AM :
FlashVars doesn't work with Flash Form Application, but when I create normal Flash Project it works perfect. There is many people with the same problem and noone don't know what is problem with Flash Form Application.
I also don't know why, there is nothing in documentation about loading FlashVars with Form Application, so I think this is some bug...
extdw_doc said on Mar 14, 2008 at 11:54 AM :
For more information on why the JavaScript code is needed,
see the Active Content Developer Center: http://www.adobe.com/devnet/activecontent/

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000887.html