How to use the flashvars attribute with swfobject.embedSWF?

matt picture matt · Jul 26, 2011 · Viewed 13.5k times · Source

HTML:

<div class="playerFlashBox">
    <object width="800" height="450" type="application/x-shockwave-flash" id="playerSWF" name="playerSWF" data="/flash/Player.swf" >
        <param name="movie" value="/flash/Player.swf">
        <param name="allowScriptAccess" value="sameDomain" />
        <param name="allowFullScreen" value="true" />
        <param name="quality" value="high" />
        <param name="wmode" value="opaque">
        <param name="FlashVars" value="ProjectId=<%= @project.id.to_s %>&amp;Language=<%= @locale %>" />
        <embed width="800" height="450" type="application/x-shockwave-flash" id="playerSWF" name="playerSWF" src="/flash/Player.swf" class="playerBox"
            allowScriptAccess="sameDomain"
            allowFullScreen="true"
            quality="high"
            flashVars="ProjectId=<%= @project.id.to_s %>&amp;Language=<%= @locale %>"
            pluginspage="http://www.adobe.com/go/getflashplayer"
        ></embed>
    </object>
</div>

Javascript:

<script type="text/javascript">
    var flashvars = {
        "ProjectId=<%= @project.id.to_s %>&amp;Language=<%= @locale %>"
    };
    var params = {
        allowScriptAccess: "sameDomain", 
        allowFullScreen: "true",
        wmode: "opaque",
        quality: "high",
        menu: "false"
    };
    var attributes = {}; attributes.styleclass="playerBox";

    swfobject.embedSWF("/flash/Player.swf", "playerFlashBox", "800", "450", "9.0.0","expressInstall.swf", flashvars, params, attributes);
</script>

I want to replace this with a clean swfobject statement. I just have no clue how to work with the flashvars attribute. Any ideas?

Answer

shanethehat picture shanethehat · Jul 26, 2011

you create it as an object like the params and attributes:

var flashvars = {
    PrjectId:"<%= @project.id.to_s %>",
    Language:"<%= @locale %>"
};