Search code examples
flashdynamicscaleswfobject

SWFObject 2.0 Dynamic Scaling


I'm trying to do something a little different with my flash embedding on an HTML page. I added an option to the right click context menu to toggle between two scales modes: noscale and exactfit. This works when I run the swf as a standalone but not within an HTML page. Does anyone have any ideas if there a way to embed a swf and dynamically change the scale mode? Perhaps embedding with 100% width and height? However I tried that and it breaks the embed javascript code.

<script type="text/javascript">
    var params = {};
    params.scale = "exactfit"
    var flashVars = {};
    swfobject.embedSWF("UserInterfaceStagingCR.swf", "myContent", "1440", "900", "9", null, flashVars, params);
</script>

Solution

  • See this post about resizing a SWF set to 100% width/height.

    But if you want to switch from noScale to exactFit (and vice-versa), you probably need to edit the param node in your JavaScript.

    I've never actually tried it (I'm not sure if it will work), but here's what I'd experiment with:

    function setScaleMode(mode){
    
        var paramNodes = document.getElementsByTagName("param");
    
        for(var i=0, len=paramNodes.length; i<len; i++){
            var node = paramNodes[i];
            if(node.name === "scale"){
                //switch to whatever scale mode you want to use.
                node.value = mode;
                //exit loop
                return;
            }
        }
    
    }
    
    var params = { scale: "exactfit" };
    var flashVars = {};
    
    swfobject.embedSWF("UserInterfaceStagingCR.swf", "myContent", "1440", "900", "9", false, flashVars, params);
    

    (Of course, this code would need to be modified if you have multiple SWFs on a page.)

    Then have your ActionScript invoke the JavaScript via ExternalInterface:

    ExternalInterface.call("setScaleMode", "noscale");