Not signed in (Sign In)

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

    • CommentAuthorlongmuir
    • CommentTimeMay 7th 2007
     
    hi all

    i have a swf that isembedded using the swfobject and works fine......but

    i want to be able to swap the swf for another by selecting a html link from a list

    is this possible?????

    any help appreciated

    thanks
    • CommentAuthorAran
    • CommentTimeMay 7th 2007
     
    This question comes up a bit. Up till now I've been telling people to use iframes to do it, but I thought I'd whip up a bit of test file to see if I could do it all on the same page. I did a similar thing using Ajax a while ago, so I thought I'd try a pure client side solution. The below works all the browsers I had access to:

    PC:
    IE 6
    IE 7
    Firefox 2.0

    MAC:
    Firefox 2.0
    Safari
    Camino
    Shiira

    Now you'll see that I am loading the same dimensioned swf's in my setFlash() function, but you could add extra params to take in w/h, version, colour etc.

    <html>
    <head>
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">

    function setFlash( loc )
    {
    var so = new SWFObject(loc, "pullContent", "425", "350", "8", "#ffffff");
    // wmode opaque needed to make youtube videos scroll correctly
    // see http://blog.deconcept.com/swfobject/forum/discussion/327/
    so.addParam("wmode", "opaque");
    so.write("flashcontent");
    }

    </script>

    </head>
    <body>
    <div id="flashcontent">
    Click a button to load content
    </div>

    <p>
    <form name="form1" method="post" action="" >
    <input type="button" name="Button" value="content 1" onClick="javascript:setFlash('http://www.youtube.com/v/TC7gXmMPKUc');">
    <input type="button" name="Button2" value="content 2" onClick="javascript:setFlash('http://www.youtube.com/v/6gmP4nk0EOE');">
    </form>
    </p>
    </body>
    </html>
    • CommentAuthorlongmuir
    • CommentTimeMay 8th 2007
     
    hmmm....so how do i make say 3 swfobjects from my swf in my root.

    then call them with the links...

    sorry im not up to scratch with my js!!!

    something like this??

    <html>
    <head>
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">

    function setFlash( loc )
    {
    var so = new SWFObject("swf1.swf", "swf1", "425", "350", "8", "#ffffff");
    var so = new SWFObject("swf2.swf", "swf2", "425", "350", "8", "#ffffff");
    var so = new SWFObject("swf3.swf", "swf3", "425", "350", "8", "#ffffff");
    // wmode opaque needed to make youtube videos scroll correctly
    // see http://blog.deconcept.com/swfobject/forum/discussion/327/
    so.addParam("wmode", "opaque");
    so.write("flashcontent");
    }

    </script>

    </head>
    <body>
    <div id="flashcontent">
    Click a button to load content
    </div>


    <li><a href="#" id="swf1" onclick="javascript:setFlash('swf1');">SWF 1</a></li>
    <li><a href="#" id="swf3" onclick="javascript:setFlash('swf2');">SWF 2</a></li>
    <li><a href="#" id="swf3" onclick="javascript:setFlash('swf3');">SWF 3</a></li>


    </body>
    </html>
    • CommentAuthorlongmuir
    • CommentTimeMay 8th 2007
     
    sorry, this is right.......but doesnt seem to work using text links tho, only using the input form

    <html>
    <head>
    <script type="text/javascript" src="swfobject.js"></script>
    <script type="text/javascript">

    function setFlash( loc )
    {
    var so = new SWFObject(loc, "pullContent", "365", "452", "8", "#ffffff");
    // wmode opaque needed to make youtube videos scroll correctly
    // see http://blog.deconcept.com/swfobject/forum/discussion/327/
    so.addParam("wmode", "opaque");
    so.write("flashcontent");
    }

    </script>

    </head>
    <body>
    <div id="flashcontent">
    Click a button to load content
    </div>

    <p>
    <form name="form1" method="post" action="" >
    <input type="button" name="Button" value="content 1" onClick="javascript:setFlash('swf1.swf');">
    <input type="button" name="Button2" value="content 2" onClick="javascript:setFlash('swf2.swf');">
    <input type="button" name="Button2" value="content 2" onClick="javascript:setFlash('swf3.swf');">
    </form>


    </p>
    </body>
    </html>
    • CommentAuthorphilip
    • CommentTimeMay 8th 2007
     
    What you wrote earlier ("so how do i make say 3 swfobjects from my swf in my root") sounds like you're trying to load a SWF into another SWF.

    SWFObject is designed to embed a SWF onto an HTML page, and to pass variables during the load process. SWFObject can't be used to pass variables at any time other than when it first loads.

    If you're trying to load a SWF into another SWF, you should use your form ("form1") to communicate with the container SWF. Flash's ExternalInterface Class enables you to set up two-way Javascript-Actionscript communication (a great example is at http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_15683).

    If you meant that you want to replace the SWF embedded on your HTML page with another SWF, you'd continue to use Aran's example posted above.

    Some notes:
    Check your filepath... is 'swf1.swf' the correct filepath (no nested folders?).

    Your button names and values are conflicting:
    <input type="button" name="Button2" value="content 2" onClick="javascript:setFlash('swf2.swf');">
    <input type="button" name="Button2" value="content 2" onClick="javascript:setFlash('swf3.swf');">

    The last one should be:
    <input type="button" name="Button3" value="content 3" onClick="javascript:setFlash('swf3.swf');">

    Actually, you don't need to use "javascript:" in an onclick call... just put your function: onClick="setFlash('swf1.swf');". So your buttons should look like this:

    <form name="form1" method="post" action="" >
    <input type="button" name="Button1" value="content 1" onClick="setFlash('swf1.swf');">
    <input type="button" name="Button2" value="content 2" onClick="setFlash('swf2.swf');">
    <input type="button" name="Button3" value="content 3" onClick="setFlash('swf3.swf');">
    </form>

    - philip
    • CommentAuthorlongmuir
    • CommentTimeMay 8th 2007
     
    works fine - thanks for your help guys :)