Not signed in (Sign In)

Vanilla 1.0.3 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorfiann
    • CommentTimeOct 4th 2007 edited
     
    I have been using SWFObject on a page which also uses the JSON.js library from http://www.json.org/ - I believe this will also apply to the Prototype.js library.

    There is a problem with this because the JSON library adds properties to the global Object prototype. SWFObject includes some unsafe for/in loops to append parameters and vars to the html. Functions on the object prototype are converted to text and then placed into the embed tag, causing corrupt html.

    There is more explanation of the problem at http://yuiblog.com/blog/2006/09/26/for-in-intrigue/ and I have a patch available for SWFObject 1.5 for anyone else who is encountering this problem.
    • CommentAuthorfiann
    • CommentTimeOct 4th 2007 edited
     
    Hopefully this will make it past the filter - here is a patch for the source version of SWFObject 1.5 source version.

    Index: C:/html/clients/.../js/swfobject.js
    ===================================================================
    --- C:/html/clients/.../js/swfobject.js (revision 20922)
    +++ C:/html/clients/.../js/swfobject.js (working copy)
    @@ -75,7 +75,9 @@
    var key;
    var variables = this.getVariables();
    for(key in variables){
    - variablePairs[variablePairs.length] = key +"="+ variables[key];
    + if (typeof variables[key] == "string" || typeof variables[key] == "number") {
    + variablePairs[variablePairs.length] = key +"="+ variables[key];
    + }
    }
    return variablePairs;
    },
    @@ -89,7 +91,11 @@
    swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ (this.getAttribute('style') || "") +'"';
    swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
    var params = this.getParams();
    - for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
    + for(var key in params){
    + if (typeof params[key] == "string" || typeof params[key] == "number") {
    + swfNode += [key] +'="'+ params[key] +'" ';
    + }
    + }
    var pairs = this.getVariablePairs().join("&");
    if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
    swfNode += '/>';
    @@ -102,7 +108,9 @@
    swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
    var params = this.getParams();
    for(var key in params) {
    - swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
    + if (typeof params[key] == "string" || typeof params[key] == "number") {
    + swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
    + }
    }
    var pairs = this.getVariablePairs().join("&");
    if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
    • CommentAuthorAran
    • CommentTimeOct 5th 2007 edited
     
    Fiann

    Just to summarise to everyone reading - you are just need to put in an extra if statement to make sure we are only adding properties which are a string or number type to the object/embed code yes?

    I know a few people have been banging their heads with incompatibilities with other libraries. It would be great if the above dealt with the majority of the issues :)

    Geoff, can we look at making this mod?

    As an related aside, I know flash itself had some similar issues (being prototype based also), and you could do tricky things with an undocumeted function assetpropflags. See more here if anyone is interested: http://www.flashguru.co.uk/assetpropflags/.