Results 1 to 19 of 19
  1. #1

    Auto-detect flash width/height?

    Im adding a flash game section to my site, and Im have trouble with getting my script to properly display .swf files. I noticed if you don't include width/height parameters, swf files don't behave like images and simply display their actual 1:1 size. width/height have to be coded into html, or the html generated by the php script. I could add width/height fields and specify them for every flash file I add, but there has to be an easier way!

    is there a way to auto-detect the true dimensions of the flash file, or simply displaying it 1:1 on the page without hard-coding the dimensions?

    Right now, my code to include the flash file is:

    PHP Code:
    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="600" height="450" align="center">
              <PARAM NAME=movie VALUE="http://www.omfgmedia.com/games/<? echo $filename?>">
              <PARAM NAME=quality VALUE=high>
              <PARAM NAME=bgcolor VALUE=#FFFFFF>
              <EMBED src="http://www.omfgmedia.com/games/<? echo $filename?>" width="600" height="450" quality=high TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"> </EMBED>
            </OBJECT>

  2. #2
    Join Date
    Mar 2005
    Posts
    48
    the height/width can be determined with javascript.

  3. #3
    Mind shedding some light on how one would do that?

  4. #4
    Join Date
    Mar 2005
    Posts
    48
    It's literally 2 lines of javascript to detect and resize.

    Let me put together a demo page and I'll post the link.

  5. #5
    Would be much appreciated.

  6. #6
    Join Date
    Mar 2005
    Posts
    48

    Re: Auto-detect flash width/height?

    Originally posted by o2pb

    Right now, my code to include the flash file is:

    PHP Code:
    <OBJECT ID="YOURFRIGGINFLASHFILE" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="600" height="450" align="center">
              <PARAM NAME=movie VALUE="http://www.omfgmedia.com/games/<? echo $filename?>">
              <PARAM NAME=quality VALUE=high>
              <PARAM NAME=bgcolor VALUE=#FFFFFF>
              <EMBED src="http://www.omfgmedia.com/games/<? echo $filename?>" width="600" height="450" quality=high TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"> </EMBED>
            </OBJECT>
    too lazy to come up with an example page, so here's the javascript, just call the function AFTER the flash has been loaded. You can use javascript to determine if/when the flash file has loaded, but that's another topic.
    PHP Code:
    <script type="text/javascript">
    function 
    resizeFlash() {   
       
    // document.getElementById() is not supported by a few browsers
       // the point here is to get a reference to your flash object
       // you should substitute with more intelligent browser detection
       
    var theFlash document.getElementById('YOURFRIGGINFLASHFILE');
       
    theFlash.width parseInt(theFlash.TGetProperty('/',8) + "px";
       
    theFlash.height parseInt(theFlash.TGetProperty('/',9) + "px";
    }
    </script> 
    I'm typing this code from memory, so there may be some typos.

  7. #7
    Join Date
    Mar 2005
    Posts
    48
    note: this works on safari, firefox, IE 6

    but you have to change the object/embed declaration to suit the appropriate browser.

  8. #8
    Well, I just tried puting your code after the embed tag, and substituting the swf file URL, but it didn't work. Absolutly no impact on the displaying of the file.

  9. #9
    Join Date
    Mar 2005
    Posts
    48
    Just putting the code there isn't going to resize it.
    You have to execute the code. i.e.

    PHP Code:

    <a href="#" onclick="resizeFlash(); return false;">resize</a
    The link above is just an example. The important thing is that :
    1. you need to execute the resizeFlash() function
    2. the function needs to be executed AFTER the flash file has completely finished loading.

  10. #10
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    239
    Shouldn't the actual flash <embed> tag have some sort of a variable which javascript substitutes?

  11. #11
    Join Date
    Mar 2005
    Posts
    48
    the only tricky part is obtaining a reference to the flash file.
    That is very browser specific.

    Once you have done that, then the above code will work just fine.

    i.e.

    take out the object declaration and just use embed with an ID attribute set to YOURFRIGGINFLASHFILE
    the resizeFlash() function will now work for non IE browsers.
    This logic (object vs. embed) can be performed by the php code.

    PHP Code:
    <EMBED id="YOURFRIGGINFLASHFILE" src="http://www.omfgmedia.com/games/<? echo $filename?>"  quality=high TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"> </EMBED>

  12. #12
    m trying to get this example working too.
    Can you post more information?

  13. #13
    Join Date
    Mar 2005
    Posts
    48
    I guess I do have to put a sample page together.
    patience please.

  14. #14
    my main problem is passing js variables to php in order to effectively resize the swf file in the browser before display.

  15. #15
    Bump! Still waiting for a sample page.

  16. #16
    Join Date
    Mar 2005
    Posts
    48
    Sorry, been busy (moved to different vps provider).
    I'll see about working on it this weekend.

  17. #17
    Join Date
    Mar 2005
    Posts
    48
    Update:
    Tried to create auto-resize demo. Found that some flash movies use a trick where the width/height is much larger than what the final movie will be. This allows for effects like flying text, objects etc.
    What the larger file dimensions means is that you will see the movie as the developer sees it, not as the end user is supposed to see it.
    So... not gonna happen anytime soon.

  18. #18
    Join Date
    Apr 2004
    Location
    St. Petersburg
    Posts
    6

    Wink SWF Header Parser - Detecting Flash Movie Width, Height etc.

    You may want to use this app for detecting Flash movie's width & height:

    http://navin.biz/files/SWFParser.zip

    It's a free tool written in C# (.NET Framework 2.0) and contains all source code.

    http://navin.biz/files/SWFParser.png

    P.S.: There is no way correctly detecting Flash movie's width & height with JavaScript, you may only do this by parsing SWF file on a server side.

  19. #19
    Join Date
    Sep 2005
    Location
    India
    Posts
    750
    Why don't you set the width and height using PHP just like you are setting the movie name.

    PHP Code:
    <? echo $filename?>
    This may may include a slightly more work for you on the PHP backend, but it will not be dependant on JavaScript and hence will work with all browsers.
    Darsh Web Solutions : Web Design, PHP Development, E-Commerce Solutions

    PHP Tutorials : Tutorials and scripts for beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •