FlashVar Purgatory
October 15, 2007 11:58 AM   Subscribe

FlashVars & "GET" style URL encoding - help?!

I have a website that features a really simple Flash movie which contains an FLV player that is driven by a Tree component, which has its entries defined by an XML file. This is all fantastic, really easy, was not that hard for me to code/design/setup by viewing a few tutorials...

However, the time has come to expand the capacity of this Media page. I need to modify the Action Script to accept a Flash Variable that is provided IN AN URL like this:

The normal page is foo.com/foo.html

I want to link to this page with an url such as foo.com/foo.html?videoPlayer=thisfile.flv

With the intended functionality being that when the page is rendered the SWF file interprets the string and performs the correct action.

You'd think this would be simple, but I cannot find suitable instructions on how to do this. I have found a thousand different solutions to encoding these flashvar calls in the OBJECT and EMBED sections of the HTML in which the SWF is rendered, but this is not what I want to do. The HTML for the page has to remain static.

It doesn't help that I'm not much of a coder, but I think I can do it with a slight shove in the right direction! Flash experts, hope me!
posted by prostyle to Computers & Internet (3 answers total)
 
Javascript can get at the querystring values and pass it into flash. Your flash file is embedded in an HTML page that can execute javascript. Use Actionscript's "ExternalInterface" to call some javascript like this in the containing page and pass the value into flash.

Alternately, you could use DOM manipulation to add the value to the object/embed tags when the DOM becomes available. In this scenario, you are using JavaScript to format the object/embed tags "on-the-fly" to the format you've seen in the tutorials you mention.
posted by drinkspiller at 12:10 PM on October 15, 2007


SWFObject can take care of this for you. You'll want to use something like:

so.addVariable("flashvar1", getQueryParamValue("queryvar1"));
posted by thinman at 1:25 PM on October 15, 2007


Another vote for SWFObject, it'll neatly handle detection, embedding, reading the value from the query string, and passing it into the Flash movie.
posted by malevolent at 3:08 PM on October 15, 2007


« Older Mr. Bento you're a bloodthirsty foe, but your...   |   Looking for the Lord's Homies Newer »
This thread is closed to new comments.