views:

141

answers:

2

IS there a clean and concise way to put multiple swfobjects into one page in HTMl, bearing in mind they will all need different flashvars?

Below is just one:

<script type="text/javascript">
            var flashvars = {};
            var params = {};
            var attributes = {};
            swfobject.embedSWF("/swf/AllBookings.swf", "no-flash", "620", "365", "9.0.0", false, flashvars, params, "all_bookings");
</script>

I could copy and paste this a few times and change the names, but there must be a nice way.

A: 

You only need to copy and paste this part:

swfobject.embedSWF("/swf/AllBookings.swf", "no-flash", "620", "365", "9.0.0", false, flashvars, params, "all_bookings");
Jon Winstanley
+1  A: 

Put all relevant parameters into an array and iterate over it:

var swfs = [
    {
        url: '/swf/AllBookings.swf',
        id: 'no-flash',
        width: 620,
        height: 365,
        flashvars: {},
        params: {},
        attributes: {}
    },
    {
        url: '/foo.swf',
        id: 'bar',
        width: 620,
        height: 365,
        flashvars: {},
        params: {},
        attributes: {}
    }
];

for (var i = 0; i < swfs.length; i++) {
    var swf = swfs[i];
    swfobject.embedSWF(
        swf.url, swf.id, swf.width, swf.height, "9.0.0", false, 
        swf.flashvars, sfw.params, swf.attributes
    );
};
jou