I need to pass a variable to a Flash movie on a page with the following address
clients.idea-bureau.com/cabanagrille/menu.html?page=lunch
so Flash can display lunch menu of a restaurant on the menu.html page. I've heard you don't have to use Flash vars for this anymore and can get the variable into Flash directly? Any thoughts?
unata 2008.04.30, 02:28AM — pass variable from URL
unata 2008.05.02, 06:44PM —
if anyone else is looking, this is the info I could find. From what I understand, the variables from the URL are available to the root timeline, but only if you call .swf file directly and not HTML file.
ask.metafilter.com/52398/Passing-Variables-to-Flash-with-URLs
which does not apply to my case. The article above recommends to use SWFObject.
I also found this piece of code, but I have no idea what it does and I was not able to get it to work. Anybody?
var queryParts : Array = flash.external.ExternalInterface.call( "function() { return window.location.toString(); }" ).split( "?" )[ 1 ].split( "=" );
trace( queryParts[ 0 ] + " = " + queryParts[ 1 ] ); // outputs "url = audio_file.mp3"
persist 2008.05.03, 12:16AM —
zomg! persist is here. shhh
I couldn't let this question go.
Using SWFOBJECT, which you should be doing anyways to deploy your swfs, giving a swf page vars is a simple matter of setting a parameter to expose the root timeline to the value.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>SWFObject v2.0 dynamic embed - step 3</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<div id="myContent">
<p>Alternative content</p>
</div>
<script type="text/javascript">
var flashvars = {
myHTMLContainer = window.location.href.toString();
};
var params = {
menu: "false"
};
var attributes = {
id: "myDynamicContent",
name: "myDynamicContent"
};
swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0","expressinstall.swf", flashvars, params, attributes);
</script>
</body>
</html>
easy. this example passes the whole url. you could set it up to look for and pass each name value pair from the document.
get the js include file "swfobject.js" at code.google.com/p/swfobject/
unata 2008.05.03, 05:49AM —
Hey, Persist, thank you, I got SWFObject to work (used it before but not for passing variables) and all is good. What is this though, just curious
flash.external.ExternalInterface.call ?