SWFObject v2.0 acts different compared to v1.5 (code example inside)

85 views
Skip to first unread message

DDJ

unread,
Dec 5, 2007, 4:37:23 PM12/5/07
to SWFObject
Hello, I switched from SWFObject v1.5 to v2.0 but I can't make the new
version working as the previous one on my site. I have some particolar
needs on my site so that I need to load a flash movie on a page only
when someone clicks on a link. To better exaplain what i mean, I've
made a small test page to show the problem and compare both v1.5 and
v2.0. Using the code below, v2.0 seems to load the movie just on the
first click then it stops and you can't reload it anymore. But I can
reload the movie as long as I want clicking on the link with the old
v1.5 (and that's what I need). Could someone please suggest me a way
to make v2.0 act like v1.5? Thank you very much!

Here's the full page code:

<html>
<head>
<title>SWFObjects</title>
</head>

<body>
<script type="text/javascript" src="swfobject15.js"></script>
<script type="text/javascript" src="swfobject20.js"></script>

<script type="text/javascript">
function swfobject15()
{
so = new SWFObject('mymovie.swf', 'mymovie', '400', '400', '7');
so.write('movie');
}

function swfobject20()
{
flashvars = false;
params = false;
attributes = false;
swfobject.embedSWF('mymovie.swf', 'movie', '400', '400', '7.0.0',
flashvars, params, attributes);
}
</script>

<div id="movie"></div>

<a href="javascript: swfobject15()">Old SWFObject</a>
<br>
<a href="javascript: swfobject20()">New SWFObject</a>

</body>
</html>

Bobby

unread,
Dec 5, 2007, 6:03:56 PM12/5/07
to SWFObject
Related to thread: http://groups.google.com/group/swfobject/browse_thread/thread/6aa4458a4028506

SWFObject 2.0 will replace your <div id="movie"></div> with your Flash
content, while SWFObject 1.5 and UFO replace the content inside the
container.

If you want to be able to replace this Flash content with new Flash
content by clicking a link, you should assign it the same id as your
HTML container (the first replaces the latter, so your id will stay
unique), so SWFObject 2.0 can reference the element and replace it.
Please let me know if this works for you.

Furthermore, if possible, please move your script blocks to the head
of your HTML file. Also, you could write your function as:
function swfobject20()
{
swfobject.embedSWF('mymovie.swf', 'movie', '400', '400', '7.0.0',
false, false, { id:movie });

DDJ

unread,
Dec 6, 2007, 2:58:01 AM12/6/07
to SWFObject
Thanks Bobby for your reply! However it still doesn't work... :( I
assigned the id to the movie like below but still doesn't work and
doesn't replace Flash content.... any help?

------------------------------------------------------------------------------------------------------------------------------------

<script type="text/javascript">
function swfobject20()
{
flashvars = false;
params = false;
attributes = { id: 'movie' };

swfobject.embedSWF('mymovie.swf', 'movie', '400', '400', '7.0.0',
flashvars, params, attributes);
}
</script>

<div id="movie"></div>

------------------------------------------------------------------------------------------------------------------------------------

Bobby

unread,
Dec 6, 2007, 5:45:58 AM12/6/07
to SWFObject
Sorry, my bad, I forgot the express install parameter. I made a test
case and it works ok:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
function replace() {
swfobject.embedSWF("test.swf", "myContent", "300", "120", "9.0.0",
"expressInstall.swf", false, false, {id:"myContent"});
}
</script>
</head>
<body>
<div id="myContent">alternative content</div>
<a href="javascript:replace()">replace</a>
</body>
</html>

DDJ

unread,
Dec 6, 2007, 6:31:02 AM12/6/07
to SWFObject
Thank you, it works fine now! :)

DDJ

unread,
Dec 7, 2007, 9:56:00 AM12/7/07
to SWFObject
Here I am again, I have another problem... :( Please Bobby test the
code below and look how it behaves: I can't make SWFObject 2.0 work
like version 1.5. It seems to not consider the tag "position:
absolute" inside the div.

Here's the code:


----------------------------------------------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>SWFObject test page</title>

<script type="text/javascript" src="swfobject15.js"></script>
<script type="text/javascript" src="swfobject20.js"></script>

<script type="text/javascript">
function swfobject15()
{
so = new SWFObject('http://www.lukamaras.com/tutorials/cool-design/
media/example-3-D-logo.swf', 'movie', '200', '200', '7');
so.addParam('quality', 'high');
so.addParam('menu', 'false');
so.write('movie');
}

function swfobject20()
{
expressinstall_url = false;
flashvars = false;
params = { quality: 'high', menu: 'false' };
attributes = { id: 'movie' };

swfobject.embedSWF('http://www.lukamaras.com/tutorials/cool-design/
media/example-3-D-logo.swf', 'movie', '200', '200', '7.0.0',
expressinstall_url, flashvars, params, attributes);
}
</script>
</head>

<body bgcolor="#000000">
<div id="movie" style="position: absolute; top: 150px; left:
350px"></div>

<br><br><br><br><br><br>

<a href="javascript: swfobject20()"><b>TEST IT!</b></a></td>

</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------


Any help? Thank you!

Bobby

unread,
Dec 10, 2007, 6:03:17 AM12/10/07
to SWFObject
2 possible solutions:
1. put your style rules in an external CSS file and make them apply to
id="movie"
2. add the style attribute to your object element, like: attributes =
{ id: 'movie', style:'position: absolute; top: 150px; left:
350px' };

DDJ

unread,
Dec 10, 2007, 12:17:39 PM12/10/07
to SWFObject
You're great Bobby! It works :)
Reply all
Reply to author
Forward
0 new messages