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