I have a line like this:

<EMBED SRC="ObtainingAndBuilding_Linux.swf" WIDTH=200 HEIGHT=300</EMBED>

that I want to replace 200 and 300 by the browser window width and height.

I found some code like this which correctly gets and displays the width and height:

<HTML>
<head>
<script>
function showWH(){
if (document.all){
cW=document.body.offsetWidth
cH=document.body.offsetHeight
window.resizeTo(500,500)
barsW=500-document.body.offsetWidth
barsH=500-document.body.offsetHeight
wW=barsW+cW
wH=barsH+cH
window.resizeTo(wW,wH)
}
else
{
wW=window.outerWidth
wH=window.outerHeight
}
alert(wW+' '+wH)
}
</script>
</head>

<BODY onload="showWH()">
<EMBED SRC="ObtainingAndBuilding_Linux.swf" WIDTH=200 HEIGHT=300 quality=low loop=false TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</EMBED>

</BODY></HTML>

However, when I replace the hard coded with and height with:

WIDTH=wW HEIGHT=wH

The object gets very small (i.e. it is not any where near the window size.) Is there some syntax I am missing to get the value of these variables? (like a "${wH}" or something?)

Thanks,

David

When you say you are replacing the hardcoded values do you mean you are grabbing the embed element and dynamically setting the height and width or are you trying to use the js var's wW and wH when the embed element is initially drawn? The difference between the two is that the var's wW and wH aren't being calculated until after the embed element is already drawn. You should give the embed element an id and then use

var embedEl = document.getElementById("embedId");
embedEl.setAttribute("HEIGHT",wH);
embedEl.setAttribute("WIDTH",wW);

In the place where you are doing the alert() in your showWH function.

Ah, very cool. Thanks.

David

I thought I had the idea, but it doesn't seem to be working:

<HTML>
<head>
<script>
function showWH(){
cW=document.body.offsetWidth
cH=document.body.offsetHeight
window.resizeTo(500,500)
barsW=500-document.body.offsetWidth
barsH=500-document.body.offsetHeight
wW=barsW+cW
wH=barsH+cH
window.resizeTo(wW,wH)
var embedEl = document.getElementById("embedId");
embedEl.setAttribute("HEIGHT",wH);
embedEl.setAttribute("WIDTH",wW);
}
</script>
</head>
<BODY>
<center>
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">
<PARAM NAME=movie VALUE="ObtainingAndBuilding_Linux.swf">
<PARAM NAME=play VALUE=true>
<PARAM NAME=loop VALUE=false>
<PARAM NAME=quality VALUE=low>
<EMBED id="embedId" SRC="ObtainingAndBuilding_Linux.swf" quality=low loop=false TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</EMBED>
</OBJECT>
</center>
</BODY></HTML>

Any thoughts?

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.