/    Sign up×
Community /Pin to ProfileBookmark

Resize Flash Object

Hey there.

I’m trying to resize a flash object with some javascript, similar to the way it’s done on this site: [url]http://filippasmedhagensund.com/[/url].

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.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@robertpooleauthorMay 22.2008 — so nobody has any ideas on this? does that mean it could be a flash problem?
×

Success!

Help @robertpoole spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...