Ok if you visit http://www.miniclip.com you'll notice that there is some kind of flash rotator on the home page. This is my code attempt to move between preloaded swf animations using javascript. I've tried giving id of the object or embed but this won't help. Of course this is not that simple and the code isn't working. My intent is to have animation change when clicking the next button. Any help will be greatly appreciated.

<html>
<head>
<script type="text/javascript">

var flashNumber = 0;
var items = 3;

films = new Array(items)
films[0] = "movies/animals1.swf";
films[1] = "movies/mammyblue2.swf";
films[2] = "movies/whitebird1.swf";

function nextmovie(){
holder = document.getElementById('content');
flashNumber++;
if(flashNumber == items)
	flashNumber = 0;
holder.src = films[flashNumber];
}
</script>
</head>
<body>
<object width="400" height="300" id="content">
<param name="movie" value="animals1.swf">
<embed src = "movies/animals1.swf" name="content" 
width="400" height="300">
</embed>
</object>
<input type="button" value="next" onclick="nextmovie();" />
</body>
</html>

Recommended Answers

All 3 Replies

Your problem is that the embed tag is the one with a src property, not the object tag. Your code says

holder = document.getElementById('content'];//this grabs the object not the embed
...
holder.src = films[flashNumber]; //this line will tell the object tag to have a src of films[flashNumber] not the embed

Still not working

Interesting-a friend of mine using Firefox said that the code works but under IE and Chrome it won't work. Please give some help. What about putting the run active content script by Adobe?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">

var flashNumber = 0;
var items = 3;

films = new Array(items)
films[0] = "movies/animals1.swf";
films[1] = "movies/mammyblue2.swf";
films[2] = "movies/whitebird1.swf";

function rotate(){
holder = document.getElementById('content');
flashNumber++;
if(flashNumber == items)
    flashNumber = 0;
holder.src = films[flashNumber];
}
</script>
</head>
<body>
<object width="400" height="300">
<param name="movie" value="animals1.swf">
<embed src = "movies/animals1.swf" name="content" id="content" 
width="400" height="300">
</embed>
</object>
<input type="button" value="next" onclick="rotate();" />
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.