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.

    Overview

    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.

    Steps

    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

    Code

    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>
    </object>

    Actionscript using flashvars

    //flashvars="var1=val1&var2=val2&var3=val3";

    display("var1 = "+ var1);

    display("var2 = "+ var2);

    display("var3 = "+ var3);

    display("var4 = "+ var4);

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

    Example

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

    Source

    Download the html files and the fla and swf in this flashvars.zip

    This entry was posted in tutorial and tagged , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

    28 Comments

    1. Posted August 7, 2008 at 7:39 am | Permalink

      Hey.

      Nice example for start..!

      You have managed your blog very well :)

    2. pedro
      Posted August 22, 2008 at 3:37 am | Permalink

      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?

    3. Jason Min
      Posted November 24, 2008 at 3:31 pm | Permalink

      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′

    4. Posted January 3, 2009 at 8:25 pm | Permalink

      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.

    5. hanafi harron
      Posted March 7, 2009 at 7:57 pm | Permalink

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

    6. Posted March 27, 2009 at 12:46 pm | Permalink

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

    7. Steven
      Posted May 28, 2009 at 7:58 pm | Permalink

      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…

      • Posted May 30, 2009 at 7:31 am | Permalink

        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!

    8. G Dhurba
      Posted September 8, 2009 at 8:54 am | Permalink

      How do I load xml through flashvars?

    9. Posted September 13, 2009 at 3:06 pm | Permalink

      http://circlecube.com/2008/04/tutorial/xml-and-flash-actionscript-made-easy-parse-xml-to-object-tutorial/ – 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?)

    10. Posted January 5, 2010 at 9:38 am | Permalink

      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?

    11. Posted January 5, 2010 at 4:03 pm | Permalink

      @Tristan – notice that this is for as2. I have another tut for as3 and flashvars… http://circlecube.com/2009/12/tutorial/flashvars-and-as3/

    12. Posted February 14, 2010 at 2:44 pm | Permalink

      Hello,
      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,
      Greg

    13. Posted February 14, 2010 at 8:10 pm | Permalink

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

    14. Posted February 16, 2010 at 11:07 am | Permalink

      @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.

    15. Aleksandur
      Posted March 23, 2010 at 7:36 pm | Permalink

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

    16. Posted May 8, 2010 at 10:58 am | Permalink

      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 : http://www.madeforbeirut.com/
      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.

      Presy
      presila_presy@hotmail.com

    17. Joshua
      Posted October 23, 2010 at 12:56 am | Permalink

      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(“songs.xml”);

      to

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

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

    18. Posted January 1, 2011 at 3:36 pm | Permalink

      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?

      Thanks

      • Posted January 1, 2011 at 9:52 pm | Permalink

        @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!

    19. fahmy
      Posted January 1, 2011 at 7:46 pm | Permalink

      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?

      • Posted January 1, 2011 at 9:46 pm | Permalink

        @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
          Posted January 2, 2011 at 1:42 am | Permalink

          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.

          • Posted January 3, 2011 at 3:12 pm | Permalink

            @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

          • Posted January 8, 2011 at 6:54 pm | Permalink

            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
              Posted January 15, 2011 at 11:49 pm | Permalink

              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.

    20. Posted January 8, 2011 at 6:50 pm | Permalink

      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.

      http://www.slidedynamic.com/support/forum/4-flash-in-powerpoint/12-tutorial-passing-flashvars-to-flash-in-powerpoint

      let me know if you need more information or help.

    One Trackback

    1. [...] original video url. Plus then I don’t have to rely on javascript. I’ve written about flashvars in the past though, so I’ll leave it to you to put 2 and 2 together. Flashvars is one more [...]

    Post a Comment

    Your email is never published nor shared. Required fields are marked *

    *
    *

    You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    • Recent Posts

      WordPress updates plugin directory

      New additions to the plugin directory include: favorites, incorporating support forums into it's own tab for each plugin as well as support stats being displayed! Great! I think we also need the ability to give plugins ratings and reviews (bonus points if it can be done from within a wordpress admin dashboard when installing plugins). [...]

      Short Head

      Use zipf's short head to tune your website rather than redesign the whole thing. To make a website successful it needs to meet the needs of the users. Find out what those needs are by using the short head philosophy to equate most searched things as the biggest needs of the users. Use personas to [...]

      Img Set?

      Great article at a list apart discusing the state of the industry regarding responsive images. This picks apart the set attribute of the img element from a surprisingly objective view coming from someone so close to the picture element. Insightful discussion about the principle behind the proposals than the actual solution too. If the working [...]

      Triudo

      A mesmerizing animated triangle-ish shape form. Embedded Link triduo triduo Tweet

      Git – the paradigm shift

      A great developer story about the differences on what Git is vs other version control and what Git is not. This is how we should learn it. I heard over and over that it was distributed, but never grasped what that meant, so here are a few links and explanations that will help unlearn version [...]

      Tweening Lib comes to Javascript!

      I'm very excited to share the news that the tween library from GreenSock (hands down the best tweening library I used in flash) is not ported for use in javascript! This will be great! I missed that simple syntax from as3 when animating javascript, and now I can have my cake and eat it too. [...]

      Responsive CSS Tricks

      Here are a few useful css tricks to remember when building responsive design sites from web designer wall Embedded Link 5 Useful CSS Tricks for Responsive Design Making the design to be responsive is very easy as shown in my Responsive Design in 3 Steps tutorial, but maintaining the elements to look aesthetically balanced on [...]

      Picture element of srcset attribute?

      Bruce details the reasons and story behind the srcset attribute which is now introduced as an alternative to the picture element. Some aspects of the attribute are nice (like the fact that it's an attribute and not a new element, so it's creating up new elements with for problems. It's adapting currently used elements to [...]

      SVG Preloader with Raphael JS

      Here's a very creative use of using a newly available technology. Using svg graphics which are very lightweight, for a website preloader. I like the animation used as well. Embedded Link Make a stylish preloader with SVG | Tutorial | .net magazine Many sites neglect users with slow connections. Ian Culshaw explains how to use [...]

      CSS3 Button/Icon set

      I've been secretly hoping to see a few of these pop up once the whole icon font idea spread through the nets. I really like this idea and it's a very nice implementation too! I only see some quality issues on a couple of the icons (such as youtube), but it's awesome and I hope [...]

    • Recent Comments

      Bruce Brownlee

      Bruce Brownlee

      Ah IE6. I'd have 2 more years of sleep without IE6. Margin doubling, no properties,...
      versaena

      versaena

      how to give color at runtime…… thank you
      Mobile Websites

      Mobile Websites

      I disagree, mobile websites are the future – desktop websites and mobile websites...
      Matt Fasick

      Matt Fasick

      That's cool. I like the ripple effect as well.
      Nico

      Nico

      hi! really great job guy! very impressive.. just a question… do u have a solution to do a refresh...
      Evan Mullins

      Evan Mullins

      Agreed! I've just seen some people get pretty heated about separating all functionality...