View Full Version : changing flash movie src's dynamically,how?
Raldge
July 30th, 2006, 10:46 PM
for ex.
<object width="550" height="400">
<param name="movie" value="somefilename.swf">
<embed src="somefilename.swf" width="550" height="400">
</embed>
</object>
i wna change the src to another movie file,will it load the new movie?
thanks...
Jeff Wheeler
July 30th, 2006, 10:47 PM
Sure, just use the other file's name…
Raldge
July 30th, 2006, 10:53 PM
here's my code, it doesnt work..:(
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript">
function setMovie()
{
var swfObject = document.form1.getElementById("banner_swf");
swfObject.src = "image/pac.swf";
}
</script>
</head>
<body>
<form name="form1">
<object width="550" height="400">
<param name="movie" value=""image/m_index.swf"/>
<embed id="banner_swf" name="banner_swf" src="image/m_index.swf" width="550" height="400">
</embed>
</object>
<a href="javascript:setMovie()">change movie</a>
</form>
</body>
Jeff Wheeler
July 30th, 2006, 11:42 PM
Oh, I didn't catch that you wanted it to do it on-the-fly, but a few things that you should fix, in order for it to work:
You set the src attribute incorrectly. The correct way to do it is call the elements setAttribute method. The first argument is a string of the attribute you want to set (in this case, src), and the second arg is the value you want to set it to (in this case, image/pac.swf).
Additionally, while the preferred way to register a javascript listener is through javascript itself (i.e. declare a js block at the end of your body which registerd the onClick handler), a slightly easier (yet not quite as nice) alternative would be to use the onClick handler of the a element, and leaving href to something such as # (or blank).
In your javascript setMovie function, you never set the value attribute for the param element. I'm betting this is your problem.
Finally, you've left off the closing html tag. You need </html> at the end of your file.
Hope that helps. :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.