Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Aug 2009
    Posts
    84
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Flash Object Creator

    Code:
    function flashObject(src, id, size, params) {
        if(!src || !id || !size || !params)
            return false;
        // We have to do different stuff for IE since it's so pathetically horrible and not standards-compliant.
        var is_ie = navigator.appName == 'Microsoft Internet Explorer' ? true : false;
        var flashObject = document.createElement(is_ie ? 'embed' : 'object');
        flashObject.setAttribute('id', id);
        flashObject.style.width = size[0];
        flashObject.style.height = size[1];
        flashObject.setAttribute('type', 'application/x-shockwave-flash');
        
        if(is_ie) {
    	flashObject.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
    	flashObject.setAttribute('src', src);
        } else {
    	flashObject.setAttribute('data', src);
        }
        
        for(i = 0; i <= params.length - 1; i++) {
    	if(is_ie) {
    	    flashObject.setAttribute(params[i][0], params[i][1]);
    	} else {
    	    var param = document.createElement('param');
    	    param.setAttribute('name', params[i][0]);
    	    param.setAttribute('value', params[i][1]);
    	    flashObject.appendChild(param);
    	}
        }
        return flashObject;
    }
    What this pretty little piece of coding does is create a flash object with the ID, source, size (array - [width, height]), and parameters (array - [['paramName', 'paramValue'], ['name2', 'value2']]) that you specify.

    Example usage:
    Code:
    <span id="example">Lol.</span>
    <script type="text/javascript" src="flashObject.js"></script>
    <script type="text/javascript">// <![CDATA[
    exampleObject = flashObject('http://www.example.com/flash.swf', 'exampleObject', [200, 500], [['flashvars', 'lol&lol2=roflcakes'], ['allowFullScreen', 'true']]);
    document.getElementById('example').appendChild(exampleObject);
    // ]]>
    </script>

    I made it as a replacement to the way I was using to create my Chatango chat object in another one of my scripts, but this works well with any flash object in general.
    Last edited by orca8767; 08-30-2009 at 06:14 AM.


 

Posting Permissions

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