Counteracting Flash’s Automatic Resize
December 13, 2005
In the body, …
function writeFlash() { // Jason M. Batchelor // mori57@mac.com // Determine what client we're using... NS4=(document.layers); // The only reason we have to do this based on client-type, is because IE does not // support the use of the onResize event when there is an ActiveX control on a page. // If you want IE to automatically reload on a resize, you'll have to set up a // frameset like the one that this is contained within. if (NS4) onresize = location.reload(); // If it's Netscape, use innerWidth, if IE, document.body.clientWidth, to ascertain // the amount of screen space you have available.Do the same to retrieve the height // of the page. var winWid = (NS4) ? innerWidth : document.body.clientWidth; // -25 takes into account scrollbars. Take this out if you don't have to worry about // scrollbars on your page. winWid = winWid - 25; var winHgt = (NS4) ? innerHeight : document.body.clientHeight; winHgt = winHgt; // Create a string that contains the <OBJECT> and <EMBED> code for your Flash movie. // I've omitted the CODEBASE and PLUGINPAGE attributes, as you can get the latest attributes // when you first generate your <object> and <embed> code from within Flash. var imStr = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'" + " WIDTH='" + winWid + "' HEIGHT='" + winHgt + "' align='left'>" + " <PARAM NAME=movie VALUE='resizex.swf?scaleX=" + winWid + "&scaleY=" + winHgt + "'>" + " <PARAM NAME=quality VALUE=high>" + " <PARAM NAME=bgcolor VALUE=#FFFFFF>" + " <param name='SCALE' value='exactfit'>" + " <EMBED src='resizex.swf?scaleX=" + winWid + "&scaleY=" + winHgt + "'" + " quality=high bgcolor=#FFFFFF WIDTH='" + winWid + "'" + " HEIGHT='" + winHgt + "' TYPE='application/x-shockwave-flash'" + " align='left' scale='exactfit'>" + " </EMBED> " + " </OBJECT>"; // Now, with all the above plugged in, tell Javascript to write out the plugin code. document.write(imStr);}writeFlash(); // Call the routine, above.
In the movie clip (flash), …
onClipEvent(load){ var winWid = _root.scaleX; var winHgt = _root.scaleY; var origWid = this._width; // These are only included to show the difference, var origHgt = this._height; // and should not be needed in most cases. with(this){ _xscale = winWid != 100 ? Math.round((_root._width/winWid) * 100) : 100; _yscale = winHgt != 100 ? Math.round((_root._height/winHgt) * 100) : 100; }