This Weblog comes from Mindy McAdams and resides at Macloo.com. It's a personal blog and probably not of much interest to anyone but me. You are welcome to read and comment as you like.

November 11, 2005

FlashVars

This is a geeky Flash thing, so stop reading now if that is not your cup of tea.

Sometimes we like to make a SWF and give it to other people (e.g., students) without the FLA file. The SWF alone should run "as is." Maybe it needs to be dropped into a folder along with some external files, such as plain text, XML, some JPGs, or an MP3. But sometimes you want to let those other people customize just one or two little things. Well, you can do that with an external text file, but then the Flash file always needs to find the text file, and maybe it won't load, etc., etc.

What I wanted to make was a portable Flash button that would control an MP3 audio file. I wanted the students to be able to put multiple copies of the same SWF on one Web page.

My first thought was that I could put a copy of the SWF into a folder with one MP3 file. That way, the MP3 file can always have the same name, such as audioclip.mp3. Then the Web page calls the SWF inside the folder, the SWF loads the only MP3 that is inside its folder, and everything works without intervention.

Well. Turns out the SWF looks in the folder where the Web page is. The SWF does not go back and look inside its own little folder. Phooey!

The way around this turned out to be FlashVars, which provides a way to feed text variables to the SWF through the OBJECT code on the HTML page. Wowee! This allows us to feed in, say, a photographer's name for a slideshow. We could even feed in the name of the MP3 file. In my case, I feed in the folder name, so the SWF knows where to get its own MP3 to play.

FlashVars has been around since Flash Version 3 (!), but I didn;t know anything about it. Once again, it was searching Moock's excellent book about ActionScript that enabled me to finally find the answer.

Posted by macloo at November 11, 2005 05:55 PM
Comments