Not signed in (Sign In)

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

  1.  
    I'm trying to load, instantiate and pass arguments to swfobject using DOM scripting.

    var SWFObject = document.createElement('script');
    SWFObject.language = "javascript";
    SWFObject.type = "text/javascript";

    SWFObject.setAttribute('id','so');
    SWFObject.setAttribute('src','http://www.somewhere.com/swfobject.js');
    document.body.appendChild(SWFObject);

    This seems to work. My question: how do I pass the arguments and add variables?

    Mike Britton
    • CommentAuthorphilip
    • CommentTimeDec 3rd 2007
     
    that's an unusual approach. :)

    i'm not sure this is such a good idea, as:

    A) your example uses the SWFObject 'class' name (object name) for the script element, which is certain to cause issues with the proper SWFObject object, and

    B) you're using a script element to create a script element. why not just hand-code the necessary swfobject.js reference to begin with?

    it seems like an awfully complicated way to go about it. do you have an example of what you're trying to accomplish with this approach?

    - philip
  2.  
    Why is it unusual to load a remote script into a DOM script object? Regardless, the question remains unanswered.
    • CommentAuthorphilip
    • CommentTimeDec 4th 2007 edited
     
    mike

    i think it's unusual because i've never seen anyone do it with SWFObject! fair enough? :)

    the biggest catch with this method is that you can't create an instance of SWFObject until the swfobject.js file is fully loaded and ready to go. this means you must test its availability before you can try to embed a SWF.

    here's a test page i put together to demonstrate bad timing.

    here's a test page i put together to demonstrate how to check for the availability of the swfobject script before embedding the SWF (tested in WinXP: IE6, FF2, Safari 3).

    basically you need to do the following:

    function loadSWFObjectFile(){

    //create the script element
    var soLink = document.createElement('script');
    soLink.setAttribute('type', 'text/javascript');
    soLink.setAttribute('src','/scripts/swfobject.js');
    document.body.appendChild(soLink);

    //check to see if script is ready to be used
    if(soLink.readyState){ //For IE
    soLink.onreadystatechange = function () {
    if (soLink.readyState == 'complete') {
    //invoke SWFObject
    addSwf();
    }
    }
    } else { //For Firefox and Safari
    soLink.onload = function () {
    //invoke SWFObject
    addSwf();
    }
    }
    }

    //Use a separate function to declare the SO
    //instance and pass your arguments/vars

    function addSwf(){
    var so = new SWFObject('sample.swf', 'sampleSwf', '550', '400', '7', '#FFFFFF');
    so.addVariable("foo", "fighters");
    so.write("flashcontent");
    }


    hope that answers your question. :)

    - philip