Parsing FlashVars from HTML into an SWF
Author: Richard Francis | Filed under: Web DevelopmentParsing variables from HTML into Flash is really easy. I recently realised that there are a lot of unnecessarily confusing tutorials out there on how to do this so here it is, plain and simple.
To parse the variables into the SWF, simply add an extra parameter (or attribute if using the EMBED tag) to your object. The parameter/attribute name should be FlashVars and the value should look something like language=en&video=12345. The whole tag should look like this:
<param name="FlashVars" value="language=en&video=1234&file=photo.jpg" />
If you are using the EMBED tag then it should look like this (you should obviously have a lot more attributes than this):
<embed src="mymovie.swf" FlashVars="language=en&video=1234&file=photo.jpg"></embed>
Now for the actionscript part. You can access these variables by calling them from the root of your document (they are parsed into the top level of your movie). For ActionScript 2.0 you can call it like so:
myMovieClip.loadMovie(_root.file);
This will load photo.jpg into the specified move clip. Now I’m not a pro in ActionScript 3.0 and I don’t think you can use the loadMovie method so providing you can find the correct way to load an image, you would just reference root.file instead of _root.file (drop the underscore).
Tags: Flash
































Leave a Reply