SWF rotator

53 views
Skip to first unread message

mikek12003

unread,
Mar 6, 2011, 2:52:58 PM3/6/11
to SWFObject
Try to create an SWF rotator, in JS within a given set interval I use
swfobject.embedSWF() to change the content of the target div. I had
little time to read the documentation, is this way of embedding the
best? more important do I have after each of these calls to embed a
SWF to call someother to un-embeded before embeded the next swf? (even
like this works fine but read somewhere if exists you must do it to
free some memory) is there a buid-in way of doing this rotation?

Thanks in advance
Mike

Sam Sherlock

unread,
Mar 6, 2011, 6:32:07 PM3/6/11
to swfo...@googlegroups.com, mikek12003
embedSWF is for when page runs

use createSWF to insert swf into a div after page load

here is something adjusted from an past project, I was using links to enable user to replace
the targetObj from a list of available items; this uses jquery to enable things


var loadObj = function (e) {
    e.preventDefault();
   
    replaceSwfWithEmptyDiv('trgtObj');
   
    // create the swf get
    targetObj = swfobject.createSWF({ data:"target.swf", width:"300", height:"300" }, par, "trgtObj");
    $(targetObj).css('visibility', 'visible');
};


function replaceSwfWithEmptyDiv(targetID) {
    var el = document.getElementById(targetID);
    if(el){
        var div = document.createElement("div");
        el.parentNode.insertBefore(div, el);
        //Remove the SWF
        swfobject.removeSWF(targetID);
        //Give the new DIV the old element's ID
        div.setAttribute("id", targetID);
    }
}

$(document).ready(function () {
    var objLinks = $('#objBox ul').find('.playObjLinks');
    objLinks.live('click', loadObj);
});

 - S





--
You received this message because you are subscribed to the Google Groups "SWFObject" group.
To post to this group, send email to swfo...@googlegroups.com.
To unsubscribe from this group, send email to swfobject+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/swfobject?hl=en.


mikek12003

unread,
Mar 7, 2011, 9:06:38 AM3/7/11
to SWFObject
So I use embedSWF for the first swf and then createSWF/removeSWF for
all the others?
My code is this:

<html>
<head>
<style type="text/css">
body{
background-color: #00CC99
}
</style>
<script type="text/javascript" src="swfobject.js"></script>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></
script>
<script type="text/javascript">

clock(1);

function clock(i)
{

if (i<4) j=i+1;
else j=1;

if (i=='1')
{
swfobject.embedSWF("gmlogoB.swf", "myContent", "779", "136",
"9.0.0");
setTimeout("clock(j)",3000);
}
else if (i=='2')
{
swfobject.embedSWF("468x60_diakopes.swf", "myContent", "468", "60",
"9.0.0");
setTimeout("clock(j)",1250);
}
else if (i=='3')
{
swfobject.embedSWF("gmlogoA.swf", "myContent", "779", "136",
"9.0.0");
setTimeout("clock(j)",1250);
}
else if (i=='4')
{
swfobject.embedSWF("eede.swf", "myContent", "468", "60", "9.0.0");
setTimeout("clock(j)",1250);
}
//alert("j is"+ j);

}
</script>

</head>
<body>



<table style="width:1000px; height:200px;">
<tr>
<td style="background-color:#0000CC;" align="center" valign="middle">
<div id="myContent" >
<h1>Alternative content</h1>
<p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/
get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
</div>
</td>
</tr>
</table>
<br/>

</body>
</html>


P.S Also to detect if javascript is enable or not use the <noscript>
tag?

Sam Sherlock

unread,
Mar 7, 2011, 9:22:43 AM3/7/11
to swfo...@googlegroups.com
the inital display use embedSWF -- my past project used static rather than dynamic (still use the remove swf replace with div*)  then createSWF

<script src="Scripts/AC_
RunActiveContent.js" type="text/javascript"></
script>

you don't need the above

hasJS or other options are worth looking into (but we can't cover it here)
http://oncemade.com/adding-hasjs-class-when-javascript-is-available/
the initial display will fallback to at content in absence of js

check to see that the function your going to call to rotate works using firebug

*the function used to replace the swf with a div was posted by Aran a while back; there are some past discussions on this
worth searching for

 - S

Aran Rhee

unread,
Mar 7, 2011, 9:23:13 AM3/7/11
to swfo...@googlegroups.com, mikek12003
@Mike - If you really need to load/unload your swfs, then I suggst you read this tutorial (it will explain Sam's code a bit): 

(the 2nd part of the tut talks about why you need some clean up code etc)

You will also want to remove <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> as you are using swfobject, not the old embed js.

If the user doesn't have js, what are you actually going to do. Seeing ad your rotator needs js to work... The alt content will be shown if the user does not have Flash 9 / js, so put whatever content you want the user to see in your myContnet div


Cheers,
Aran



--
Reply all
Reply to author
Forward
0 new messages