A lot of people have heard about FlashVars and the idea of passing values into flash via HTML, but don’t know how to use it. Well there’s actually two ways of going about this.
1. Appending to the Filename
The idea here is that we append our variables onto the end of the URL from where the HTML will load the flash file. This is the “src” parameter in our <object> and <embed> tags. Just a quick point here.. The reason why we have to use both the object and embed tags is that some browsers respect one tag and some respect the other. This is due to the fact that in some browsers (Mozilla/Netscape/etc), flash is a Plugin and in IE, flash is an ActiveX Control. The different types of format require the different tags.
Note: Using this method means the swf will not be cached if the flashvars change. The SWF file will have to be re-downloaded by the user completely every time the flashvars are different.
Here we want to pass the following variables and be able to access their values on frame 1 of our movie:
greeting: “Hello world”
In the code above, the %20 represents a space character. When dealing with text in html and flash, it may contain characters, such as &, = or quotes which can cause unexpected results, so it is always safest to escape or urlencode your variables beforehand.
2. The FlashVars Parameter
The other method of passing values directly into flash is by using the FlashVars parameter in our object and embed tags. As with the first example, the FlashVars must be added to both tags in order for it to work correctly in all browsers.
We are passing the same variables as before.