Intro to Flashvars | Passing variables to actionscript from the html embed | Tutorial

I’ve had a couple special requests to explain flashvars and how to use it and show it in action.


The property “FlashVars” can be used to import root level variables to the flash movie or swf. The flashvars propery is used in codes for embedding flash in the html page. The string of variables passed in as flashvars, will be imported into the top level of the movie when it is first instantiated. Variables are created before the first frame of the SWF is played. The format of the string is a set of name=value combinations separated by ampersand (&) symbols.


  1. Include the flashvars property in your embed codes and voila! You have these variables to use in your swf.
  2. That’s the one step


HTML Embed Codes

Here's some sample embed codes, including object and embed tags:
<object width="540" height="240" title="sample">
  <param name="movie" value="flashvarsTutorial.swf" />
  <param name="flashvars" value="var1=here&var2=are&var3=my&var4=flashvars" />
  <embed src="flashvarsTutorial.swf" flashvars="var1=here&var2=are&var3=my&var4=flashvars" type="application/x-shockwave-flash" width="540" height="240" ></embed>

Actionscript using flashvars


display("var1 = "+ var1);

display("var2 = "+ var2);

display("var3 = "+ var3);

display("var4 = "+ var4);

function display(todisplay:String){
  feedback.text += todisplay+"\n";


Page 1 (var1=val1&var2=val2&var3=val3)
Page 2 (var1=here&var2=are&var3=my&var4=flashvars)


Download the html files and the fla and swf in this

This entry was posted in tutorial and tagged , , , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.
  • Inder Singh


    Nice example for start..!

    You have managed your blog very well :)

  • pedro

    Hello, I have the files and everything and i was testing around with the fla file and the html page so it will only show up var 1 and 2 but even tho when i take them out of the fla and html page var 3 and var 4 they still show up and say undefined on it.. help?

  • Jason Min

    If you use CS3 and publish html, you need to add
    In the AC_FL_RunContent code the following:

    ‘FlashVars’, ‘var1=val1&var2=val2&var3=val3′

  • Regan Rajan

    Thanks. It worked. I never knew it is so easy. I was actually messing a lot with the ActionScript 3.0 although I was only looking for something very simple like the example you provide. It was useful.

  • hanafi harron

    Your example works while others I tried don’t. Thank you so much.

    • Steven

      I just downloaded the examples and tried running everything as is and I got “undefined” for all 4 variables. I tried with CS3 and CS4, any ideas on why that happened, is there some kind of setting that I need to enable? Please help…

      • Evan Mullins

        The flashvars will show undefined if you’re running from flash. They way to pass flashvars to the swf is in the embed code. So to actually test it you have to actually put it into an html file, good luck!

        • Fryshan

          how to use flashvars in loading the mp3 files?

  • Steph Boudreau

    Thank you very much. I found this example quite clear, compared to some others loose on the interweb.

  • G Dhurba

    How do I load xml through flashvars?

  • Evan Mullins – here’s one example I’ve already written about. There are plenty of ways to do it and the best way for you may depend on a few factors (for starters, as2 or as3?)

    • Greg Miller

      The tut works great if just testing as is, but when I add the AC_FL_RunContent() script, with
      ‘flashvars’, ‘var1=here&var2=are&var3=my&var4=flashvars’,

      added in the AC code, it does not display. I’ve been searching for hours to come up with a solution that will work for FlashVars.

      Thanks much,

  • Tristan

    Nice clean tutorial and the examples work for me, but I wonder why as I can’t use the same approach in my class file.

    Why doesn’t the AS3 compiler complain that these variables are undefined?

  • Greg Miller

    Have you looked at SWFObject? It works great and gives you a variety of options for displaying your SWFs.

  • Evan Mullins

    @Greg – yes I love swfobject, it’s the only tool I use anymore for embedding flash content online. CS5 will actually use swfobject rather than AC_Active whatever trash it uses currently.

  • Aleksandur

    Hay can you make the link of banner variable and change it when you want?

  • Presy

    Hey.. I’m working on an html site with an swf navigation bar, the thing is everytime we click on one of the buttons of the navigation, the html page refresh and the button regain its initial state.
    Here is the site :
    I’ve been told to use “flashvars” but i don’t know how to do it coz i’m not developer.

    Plz if anyone can give me the code for AS2 and tell me how it’s done.. it would be soooo helpful !!
    I hope my explanation is clear.
    Thanks for ur help!!! and hope to get an answer asap.

    [email protected]

  • Joshua

    Great tut.

    I am looking for an solution to load dynamic xml files from flash using flashvars.

    In my as2 code, I want to change:


    xml.load(“$variable from flashvars.xml”);

    Is there an easy answer I am missing? I can’t find a solution anywhere.

  • Pingback: Access the html page URL and swf path from flash with as3 | circlecube()

  • Michael Storer

    I’ve looked at about six tutorials about flashvars and all have the same problem:

    None of them list the various commands that you can insert as flashvars. What the heck can I and can’t I tell my instantation to do?

    For instance, can I tell it to autostart or not? Loop? Play onmouseover? etc.
    Why don’t any of you teachers give a list?


    • Evan Mullins

      @Michael Storer – You can tell it to do anything. But it won’t do it automatically. Say you wanted to tell it to autoplay, you’d pass in a variable autoplay=true, and then in your actionscript you handle the autoplay and if it is true you have it play while if it’s false you don’t have it play. I guess no one includes all the possible commands you could put in your flashvars because they are really limitless. There is no set list of accepted flashvars, they are external settings to your internal code. So if you wanted to make something autoplay it could use any number of variables to represent that: autoplay, autoPlay, autoStart, auto, begin… it really doesn’t matter, you just have to use the same term in your actionscript. Hope that explains it well for you to get the idea, if not, I’m all ears. Best!

  • fahmy

    Dear, thanks for the above blog, i do have a question please.
    i do have a photo gallery website the swf fil html and xml are not located on the same directory the photos in this template are save in a sub folder gallery/first gallery/ example.jpg etc…..

    my problem is; every time i try to add the swf file to powerpoint it doesnt work well, because it might be somthing making the swf file to play on the html page only. can you provide any support please?

    • Evan Mullins

      @fahmy – so you have a gallery that shows up fine in an html page ina browser but you’re trying to load the gallery into a powerpoint? I’m not too familiar with powerpoint playing flash files at all, you’re loading the html through the powerpoint?

      • fahmy

        yup the SWF file is wroking fine on the HTML page, but it doesnt work on powerpoint because of some reason, may be because the SWF data are saved in diffirent folders, i’m loading the SWF file that should read from the XML file that has all the saved properities and photos path on the disk.

        • Evan Mullins

          @fahmy – I’d search around for swf display within powerpoint. I’ve seen it done before but I’ve never had the “pleasure” to work directly in powerpoint. Best of luck

        • pptvandal

          Can you explain the path or file stucture of the xml as it relates to Powerpoint. I can help explain why stuff does and dows not work in ppt when it comes to loading xml or any other external content.

          • Fahmy

            I have changed the whole presentation interface from the ppt to another software that gathers the whole flash and HTML, XML, and sources in one EXE file, it takes longer while to load but it works normally, my problem with ppt was:
            i have a very small size .SWF file that means it may not work as a stand alone file because it recalls the resources like JPGs, MP3 from another folders and subfolders something like Flash/Gallery/First gallery/Thumb/photo.Jpg and Flash/Gallery/First gallery/Image/photo2.Jpg…it has a normal XML file and i dont have the flash source to modify the way it runs.

  • pptvandal

    Here is a tutorial for passing flashvars directly to embedded shackwave flash object in ppt. You can download the example used in the video. You can also pass flashvars using VBA.

    let me know if you need more information or help.

  • Recent Posts


    What Is Code? If You Don’t Know, You Need to Read This

    Here’s a great read that may take a while but is a nice trip through programming history through the lens of one who’s been there. The world belongs to people who code. Those who don’t understand will be left behind. Source: What Is Code? If You Don’t Know, You Need to Read This Tweet

    Adactio: Journal—Instantiation

    There needs to be a cultural change in how we approach building for the web. Yes, some of the tools we choose are part of the problem, but the bigger problem is that performance still isn’t being recognised as the most important factor in how people feel about websites (and by extension, the web). This […]

    human_time_diff « WordPress Codex

    Determines the difference between two timestamps.The difference is returned in a human readable format such as “1 hour”, “5 mins”, “2 days”. Source: Function Reference/human time diff « WordPress Codex Used this little known, but nice gem today. It’s a core WordPress function that gives human relative time from any other datetime in “U” format. […]


    Cyclomatic Complexity: Logic in CSS – CSS Wizardry – CSS, OOCSS, front-end architecture, performance and more, by Harry Roberts

    I recently hit upon a way of thinking that made me realise that CSS does include logic, and the fact that it’s rarely viewed as such is probably also why we end up with such poor CSS at all.I found myself explaining compound selectors to a client as being made up of the subject—the thing […]


    Add Links to Twitter Mentions, Hashtags, and URLs with PHP

    This gem helped me out today as I was working with the Twitter API to create a custom WordPress widget. I was about to do exactly this and was not looking forward to it, luckily I did a quick search and found this webtips post. Thanks! If you’re using the Twitter v1.1 API to fetch […]

    Online regex tester and debugger: JavaScript, Python, PHP, and PCRE

    Stumbled on a great regex tool today. An explanation of your regex will be automatically generated as you type. Detailed match information will be displayed here automatically. via Online regex tester and debugger: JavaScript, Python, PHP, and PCRE. Tweet