Using Flashvars with Actionscript 3 projects
8 May, 2008
Recently I decided to try and make a generic video player that any old monkey could use to play FLV’s and other Flash compatible videos.
The obvious way (to me) to create it so that you would never need to edit the swf was to pass the path to the source video via flashvars.
Now with everything being just a little different in AS3 and not being overly familiar with it yet myself, I started to search around for the method to reference flashvars and I eventually found one very simple solution that worked perfectly:
var videoSource:String = root.loaderInfo.parameters.vidSrc;
And in the html add in the bold bits to the default Flash launcher rubbish:
<script language=”javascript”>
if (AC_FL_RunContent == 0) {
alert(“This page requires AC_RunActiveContent.js.”);
} else {
AC_FL_RunContent(
‘codebase’, ‘http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0′,
‘width’, ‘480′,
‘height’, ‘368′,
’src’, ‘videoPlayer’,
‘quality’, ‘high’,
‘pluginspage’, ‘http://www.macromedia.com/go/getflashplayer’,
‘align’, ‘middle’,
‘play’, ‘true’,
‘loop’, ‘true’,
’scale’, ’showall’,
‘wmode’, ‘window’,
‘devicefont’, ‘false’,
‘id’, ‘videoPlayer’,
‘bgcolor’, ‘#ffffff’,
‘name’, ‘videoPlayer’,
‘menu’, ‘true’,
‘allowFullScreen’, ‘true’,
‘allowScriptAccess’,’sameDomain’,
‘movie’, ‘videoPlayer’,
’salign’, ”,
‘flashvars’, ‘vidSrc=flv%DrKarl.flv’
); //end AC code
}
</script>
<noscript>
<object classid=”clsid:d27cdb6e-ae6d-11cf-96b8-444553540000″ codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0” width=”480″ height=”368″ id=”videoPlayer” align=”middle”>
<param name=”allowScriptAccess” value=”sameDomain” />
<param name=”allowFullScreen” value=”false” />
<param name=”movie” value=”videoPlayer.swf” /><param name=”flashvars” value=”vidSrc=flv%2FDrKarl.flv” /><param name=”quality” value=”high” /><param name=”bgcolor” value=”#ffffff” /> <embed src=”videoPlayer.swf” quality=”high” bgcolor=”#ffffff” width=”480″ height=”368″ name=”videoPlayer” align=”middle” allowScriptAccess=”sameDomain” allowFullScreen=”true” type=”application/x-shockwave-flash” pluginspage=”http://www.macromedia.com/go/getflashplayer” />
</object>
Note that the %2F is the code you need to use to show a slash(/) symbol.
So as long as all your values match up, this should work for you too. Remember that flashvars passes a string, so if you wanted to use numbers or something else you will need to convert it appropriately when you import it in.
Future developments could be to add the ability to pass an XML file with a playlist to make it a bit more flexible, but that job can wait for another day!
This is a good, simple explanation! Thanks!
thx!