Welcome to WebmasterWorld Guest from 184.73.126.70

Forum Moderators: open

Message Too Old, No Replies

Resize Flash Object

   
2:04 pm on May 20, 2008 (gmt 0)

5+ Year Member



Hey there.

I'm trying to resize a flash object with some javascript.

Basically I've got a massive background slideshow which I want to resize according to the window size, but without the white space, so if the window is tall and skinny the flash will be 100% in height with the sides overflowing off the screen, and if the window is short an fat have the flash 100% width with the top and bottom of the flash not shown.

I think where I'm going wrong is with the getAttribute / setAttribute but this is basically my first go with javascript so it could be riddled with errors. All I've done successfully so far is figure out the desired new height and new width for my flash element so I know that part works but the rest pretty much doesn't. Anyway, here it is:

magicRatioNumber = document.body.clientWidth / document.body.clientHeight;
var flash = document.getElementById("hayden");

if (magicRatioNumber >= 1.25) // Width needs to be 100%
{
// Calculate new height
newHeight = Math.round(document.body.clientWidth * 1.25);
newWidth = document.body.clientWidth;
flash.setAttribute("width","newWidth");
flash.setAttribute("height","newHeight");

document.write(newWidth + " x " + newHeight);
}
else // Height needs to be 100%
{
// Calculate new width
newWidth = Math.round(ocument.body.clientWidth * 0.8);
newHeight = document.body.clientHeight;
flash.setAttribute("width","newWidth");
flash.setAttribute("height","newHeight");

document.write(newWidth + " x " + newHeight);
}

hayden is the name/id for my example flash movie.

Any help/suggestions would be appreciated.

[edited by: jatar_k at 5:22 pm (utc) on May 21, 2008]
[edit reason] no urls thanks [/edit]