View Full Version : Can if / else call flash?
skimo
12-16-2008, 03:06 PM
So I have the following script which will display a different image based on the month. My question is, can this same concept be used to display a different flash piece (swf) based on the month?
Pretty much I want the exact same thing, except I want to call an swf instead of a jpg. I tried it out, but it didn't work. Is it possible with Javascript or does the if/else logic need to placed in the flash?
Thanks.
<script language="javascript" type="text/javascript">
var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var thetime = new Date();
var themonth = thetime.getMonth();
if (months[themonth] == 'June', 'July', 'August', 'September', 'October', 'November', 'December')
{
document.write('<img src="karl.jpg">');
}
else
{
document.write('<img src="gob.jpg">');
}
</script>
peep210
12-16-2008, 08:19 PM
you need to change the <img src="karl.jpg"> tag
to an <embed> or <object> tag
<embed width="WIDTH-HERE" height="HEIGHT-HERE" src="FILE-HERE.swf" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed>
or
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" WIDTH="WIDTH-HERE" HEIGHT="HEIGHT-HERE">
<PARAM NAME=movie VALUE="FILE-HERE.swf"
<embed width="WIDTH-HERE" height="HEIGHT-HERE" src="FILE-HERE.swf" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed>
</OBJECT>
skimo
12-16-2008, 11:19 PM
Thanks for the response. I tried out what you suggested, but it didn't seem to work (assuming I implemented it correctly).
You can see it in action here: http://www.benjaminkopel.com/xmas2.htm
I left the image in to show how that code works properly.
Thanks in advance for any more suggestions.
rangana
12-16-2008, 11:27 PM
Change this part:
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="650" height="100">
<param name="movie" value="Flash/Snow.swf" />
<param name="quality" value="high" />
<embed src="Flash/Snow.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="650" height="100"></embed>
</object>');
...to
document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="650" height="100"><param name="movie" value="Flash/Snow.swf" /><param name="quality" value="high" /><embed src="Flash/Snow.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="650" height="100"></embed></object>');
Do not force a line break. JS will regard it as end of line and terminates your code prematurely.
Hope that helps.
skimo
12-16-2008, 11:44 PM
Thank you for the very prompt response. That got the flash to show up, but now I seem to have a problem with the if/else. I thought it was working properly, but it doesn't seem to be...
http://www.benjaminkopel.com/xmas2.htm
I changed the:
if (months[themonth] == 'June', 'July', 'August', 'September', 'October', 'November', 'December')
to:
if (months[themonth] == 'June', 'July', 'August', 'September', 'October', 'November')
removing December to attempt to force the else statement and display the other swf (Clock.swf). However, the original swf (Snow.swf) remains.
Any ideas on that?
Thanks again.
rangana
12-16-2008, 11:48 PM
if (months[themonth] == 'June' ||
months[themonth] == 'July' ||
months[themonth] == 'August' ||
months[themonth] == 'September' ||
months[themonth] == 'October' ||
months[themonth] == 'November')
skimo
12-16-2008, 11:54 PM
Thanks Rangana.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.