View Full Version : Retrieving dimensions of an swf
Riokou
12-17-2006, 04:51 PM
Is there a way to get the dimensions of an swf file? (like, whatevergoeshere.width)
coothead
12-17-2006, 05:45 PM
Hi there Riokou,
does this help...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<base href="http://mysite.orange.co.uk/achelous/">
<style type="text/css">
body {
background-color:#444;
}
#container {
width:320px;
border-top:7px solid #000;
border-right:7px solid #333;
border-bottom:7px solid #333;
border-left:7px solid #000;
margin:100px auto;
}
#container object {
display:block;
}
</style>
<script type="text/javascript">
window.onload=function() {
alert('width="'+document.getElementById('foo').width+'px"\n\nheight="'+
document.getElementById('foo').height+'px"');
}
</script>
</head>
<body>
<div id="container">
<object id="foo" type="application/x-shockwave-flash" data="circle.swf" width="320" height="216">
<param name="movie" value="circle.swf">
<param name="quality" value="high">
<param name="menu" value="false">
</object>
</div>
</body>
</html>
Riokou
12-17-2006, 05:54 PM
Hmm, well that seems to get the dimensions of an swf on the page. I'm trying to get the dimensions of an swf so I can open a new window with its exact dimensions to put it in. I have the code that does this, but I have to type the dimensions myself every time.
coothead
12-17-2006, 06:21 PM
Hi there Riokou,
I am a liitle confused by your problem.
An .swf file can have any dimensions, as far as I know, that you set.
Here is my previous example with revised dimensions...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<base href="http://mysite.orange.co.uk/achelous/">
<style type="text/css">
body {
background-color:#444;
}
#container {
width:640px;
border-top:7px solid #000;
border-right:7px solid #333;
border-bottom:7px solid #333;
border-left:7px solid #000;
margin:100px auto;
}
#container object {
display:block;
}
</style>
<script type="text/javascript">
window.onload=function() {
alert('width="'+document.getElementById('foo').width+'px"\n\nheight="'+
document.getElementById('foo').height+'px"');
}
</script>
</head>
<body>
<div id="container">
<object id="foo" type="application/x-shockwave-flash" data="circle.swf" width="640" height="432">
<param name="movie" value="circle.swf">
<param name="quality" value="high">
<param name="menu" value="false">
</object>
</div>
</body>
</html>
If you wish it to fit in a container of fixed dimensions then set the object element's dimensions to 100%.
Riokou
12-17-2006, 06:38 PM
Sorry, let me clarify. Is there a way to retrieve the original dimentions of an swf? (so I can open a non-resizable window that will fit it perfectly) Heres the function that I use (it also centers the new window)-
function openGame(url, w, h){
centerX=screen.width/2-w/2
centerY=screen.height/2-h/2
window.open(url, '', 'width='+w+', height='+h+', scrollbars=no, resizable=no, top='+centerY+', left='+centerX+'');
return false;
}
I don't want to have to manually enter the w (width) and h (height) for every game, if there is another way.
RysChwith
12-18-2006, 09:21 AM
There are ways for Flash to communicate with JavaScript. You'd probably have to open the window to a default size, then have the SWF send its dimensions to some JavaScript that would resize the window accordingly.
I don't have a link handy, but I know Adobe's Flash site has some tutorials on making Flash and JavaScript work together. That should be able to get you started.
Rys
Riokou
12-19-2006, 08:34 PM
It seems that there isnt a way to do this, so Ill just stick to manually entering the dimensions of every file. It not that much work.. but whatever.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.