- Flash vars can be a pain. Flash vars are passed into Flash movies at load-time, and have to be formatted as a URL encoded string. The FlashTag makes setting Flash vars much easier (see code below).
- Encapsulation is good. What if you wanted to change something across all your Flash tags? Wouldn’t it be better to change it one place?
Here’s some sample code. First, load the required classes like this:
The Exception class is required so that the FlashTag class can throw exceptions if something goes wrong. Now, create an instance of the FlashTag and write it out:
// The arguments below are path, width, height, and Flash Player version number.
var tag = new FlashTag('/path/to/flashContent.swf', 300, 300, '7,0,14,0');
You can set properties like this:
You can add Flash vars like this…
tag.addFlashVar('someName', 'some value');
… or like this…
I tested it fairly well, but if you find a bug, let me know and I’ll get it fixed right away.
Update: As “sang” points out in the comments, this is also a good way to keep your pages W3C/XHTML compliant.