Passing FlashVar Strings to Flash with AS3

I found all sorts of complicated posts on the in-ter-net about this but none were clear and concise. Hopefully this will be… (but I’m no Flash expert) I basically needed to pass an xml file path to a Flash image rotator through the embed/object markup in the html file. Using FlashVars this is actually pretty easy in AS3. note: I usually use swfobject to work with Flash but this particular project called for the more “traditional” embed/object tags.

The html markup…


<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="348" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="FlashVars" value="xml_path=xml/news2.xml" /><param name="src" value="preview.swf" /><param name="flashvars" value="xml_path=xml/news2.xml" /><embed type="application/x-shockwave-flash" width="640" height="348" src="preview.swf" flashvars="xml_path=xml/news2.xml" wmode="transparent" quality="high"></embed></object>


The ActionScript code…

root.loaderInfo.parameters.xml_path;

(or if you need it in a variable…)

var xmlFilePath:String = root.loaderInfo.parameters.xml_path;

Hope that helps someone.