views:

537

answers:

1

I have many SWF file those I have included in my web page using the HTML Object tag. Its working fine but, I am not able to maintain the size of my SWF files. I have following code for SWF files.

<object id="example_flashGame" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="400">
        <param name="movie" value="/video/swf/fun/funny-baby.swf" />
        <param name="allowScriptAccess" value="always" />
        <param name="loop" value="false" />
        <param name="menu" value="false" />
        <param name="quality" value="high" />
        <param name="wmode" value="window" />

        <embed name="example_flashGame" src="/video/swf/fun/funny-baby.swf" width="600" height="400" allowScriptAccess="always" loop="false" menu="false" quality="high"  wmode="window" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"&gt;&lt;/embed&gt;
 </object>

Currently the size (width and height) of the SWF file is fixed in the object tag in above code. I want when size exceeds from a certain range then constant size will be applied to the file else, file will be displayed in its original size.

If there is a file whose size is less than what I have given in object tag then, the SWF file graphics are distorted and its not looking well.

Can anyone please tell me how can I make the size of SWF files auto if the file size is less than 600x400 if the size exceeds 600x400 then this size will apply, else file should display in its original size.

I have seen some gaming sites (such as miniclip.com) do exactly the same thing, they display the original size of there games (small or large) on play page, do they maintain there files hight and width in DB tables or something else?

Is there any way to do this in HTML or using JQuery or javascript??

+1  A: 

There's no way to simply detect the size of Flash stage from JS. You'd better call a JS function from inside Flash to set the stage size.

So, you'll have to put this code in the Flash movie (AS2):

import flash.external.ExternalInterface;
ExternalInterface.call("resizeFlash", Stage.width, Stage.height);

Then in the HTML page you'd have the JS function that resizes the Flash element:

var max_flash_width = 800;
var max_flash_height = 600;

function resizeFlash(w, h)
{
    // force the w and h to be within limits set above
    w = Math.min(w, max_flash_width);
    h = Math.min(h, max_flash_height);
    // then resize the flash element using w and h
    var flash_elem = document.getElementById("example_flashGame");
    flash_elem.width = w;
    flash_elem.height = h;
    if (navigator.userAgent.toLowerCase().indexOf("safari") !=- 1) {
        var flash_elem = document.getElementById("example_flashGame");
        flash_elem.width = w;
        flash_elem.height = h;
    }
}
Makram Saleh
I can't modify the source code because I have only SWF files.
Prashant