/    Sign up×
Community /Pin to ProfileBookmark

Using Javascript to swap a flash object

Is it possible to use Javascript to change a flash object. The following code doesn’t report any error, it just doesn’t change the object:

[code=php]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>

<html lang=”en”>
<head>

<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″>

<style type=”text/css”>
html, body, div, p, object, h1, ul{
margin:0;
padding:0;
font-size:1em;
}

div#container{
width:710px;
margin:0 auto;
}

ul.gallery{
margin-top:3em;
float:left;
list-style:none;
min-width:8em;
_width:8em;
font-weight:bold;
}

ul.gallery li{
padding: 0.2em 0;
}

ul.gallery span{
font-size: 0.7em;
padding-left: 0.6em;
font-weight:normal;
}

h1{
text-align:center;
padding:1em 0 2em 0;
font-size:large;
font-family:verdana, sans-serif;

}

p.link{
text-align:center;
padding:2em 0;
}
</style>

<script type=”text/javascript”>
function SwapMovie(input)
{
document.getElementsByTagName(‘object’)[0].data = input
document.getElementsByTagName(‘param’)[0].value = document.getElementsByTagName(‘object’)[0].data
return false;
}
</script>

<title>Nicolás &amp; Sofía</title>

</head>

<body>
<div id=container>
<h1>Nicolás &amp; Sofía</h1>

<ul class=”gallery”>
<li><a href=”?i=0″ onclick=”return SwapMovie(‘./video1.swf’)”>Video1</a> <span>306 kB</span></li>
<li><a href=”?i=1″ onclick=”return SwapMovie(‘./video2.swf’)”>Video2</a> <span>289 kB</span></li>
<li><a href=”?i=2″ onclick=”return SwapMovie(‘./video3.swf’)”>Video3</a> <span>202 kB</span></li>
<li><a href=”?i=3″ onclick=”return SwapMovie(‘./video4.swf’)”>Video4</a> <span>341 kB</span></li>
<li><a href=”?i=4″ onclick=”return SwapMovie(‘./video5.swf’)”>Video5</a> <span>357 kB</span></li>
<li><a href=”?i=5″ onclick=”return SwapMovie(‘./video6.swf’)”>Video6</a> <span>1086 kB</span></li>
</ul>

<p class=”gallery”><object type=”application/x-shockwave-flash” data=”./video1.swf” width=”576″ height=”460″><param name=”movie” value=”./video1.swf”></object></p>

</div>
</body>
</html>[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@chestertbNov 19.2006 — I'd be inclined to get a server-side php script to do it. Take a look at this post from earlier today as the same principle applies...

[URL=http://www.webdeveloper.com/forum/showthread.php?t=128734]http://www.webdeveloper.com/forum/showthread.php?t=128734[/URL]

It's a simple way of achieving the effect you're looking for.

CTB
Copy linkTweet thisAlerts:
@bokehauthorNov 19.2006 — I'm not looking for a server-side solution, I'm asking if Javascript can do it and why the above code doesn't do it.
Copy linkTweet thisAlerts:
@chestertbNov 19.2006 — No prob. Was just a thought.

Have you tried innerHTML?

(I don't have flash, so I can't try it before I suggest it.)

Something like...
[code=html]function SwapMovie(input)
{
flash = "<object type='application/x-shockwave-flash' data='./video1.swf' width='576' height='460'><param name='movie' value='"+input+"'></object>";
document.getElementById('flashspace').innerHTML = flash;
}

...

<p class="gallery"><span id='flashspace'><object type="application/x-shockwave-flash" data="./video1.swf" width="576" height="460"><param name="movie" value="./video1.swf"></object></span></p>[/code]


CTB
×

Success!

Help @bokeh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...