Problem with javascript function call

N

nola_dirigent

I've run into a problem trying to call a javascript function in a larger project that I'm working on. I've duplicated this problem with a simplified html and javascript page.

I'm trying to call a javascript function to play an embedded SWF file on 'onclick'. It works fine if I use an in-line javascript script call (the two links at the bottom of the html page) but I can't get it to work calling a function ( the button at the top of the page). The function seems to be finding the SWF id, but it's not playing. Ultimately, I need to transfer the function to a page where the SWF id (object) has been embedded with SWFObject 2.0. But until I can get past this hurdle, I can't go anywhere. I must be missing something rather basic here.

Any help would be appreciated.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

<script type="text/javascript">

function movie() {
var findMovie = document.getElementById('swfmovie');
if (findMovie){
findMovie.play();
} else {
alert ("Movie not found");
}
}
</script>
</head>

<body>

<p><input name="play" type="button" onClick="movie();" value="play"/><p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="219" HEIGHT="171" id="swfmovie" ALIGN>
<param NAME="movie" value="correct.swf">
<param NAME="quality" value="High">
<param name="Src" value="correct.swf">
<param name="WMode" value="Window">
<param name="allowScriptAccess" value="always" />
<param name="Play" value="false">

<EMBED src="correct.swf" quality=high bgcolor=#FFFFFF WIDTH="246" HEIGHT="187" NAME="swfmovie" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</object>
</p>

<p>
<a href="javascript:document.swfmovie.Play()"><font face="Arial">►</font>play&nbsp; </a>&nbsp;&nbsp; <font face="Arial">
<a href="javascript:document.swfmovie.StopPlay()">║pause</a></font></p>

<p>&nbsp;</p>

</body>
</html>
 
A

Arno Welzel

nola_dirigent, 2011-10-09 05:47:

Please adjust your line breaks - your lines are *way* too long. Don't
use lines much longer than 70-80 characters - thank you!
I've run into a problem trying to call a javascript function in a
larger project that I'm working on. I've duplicated this problem with
a simplified html and javascript page.

I'm trying to call a javascript function to play an embedded SWF file
on 'onclick'. It works fine if I use an in-line javascript script call
(the two links at the bottom of the html page) but I can't get it to
work calling a function ( the button at the top of the page). The
function seems to be finding the SWF id, but it's not playing.
Ultimately, I need to transfer the function to a page where the SWF
id (object) has been embedded with SWFObject 2.0. But until I can get
past this hurdle, I can't go anywhere. I must be missing something
rather basic here.

Any help would be appreciated.

I'm not sure if this is related to your problem, but:

1) You have an "ALIGN" attribute without value

2) EMBED is no valid XHTML and useless here anyway - just omit it

3) You should not use "javascript:" in your links - better:

<a href="#" onclick="document.swfmovie.Play();return false;">...
<a href="#" onclick="document.swfmovie.StopPlay();return false;">...
 
A

Arno Welzel

nola_dirigent, 2011-10-09 05:47:

Please adjust your line breaks - your lines are *way* too long. Don't
use lines much longer than 70-80 characters - thank you!
I've run into a problem trying to call a javascript function in a
larger project that I'm working on. I've duplicated this problem with
a simplified html and javascript page.

I'm trying to call a javascript function to play an embedded SWF file
on 'onclick'. It works fine if I use an in-line javascript script call
(the two links at the bottom of the html page) but I can't get it to
work calling a function ( the button at the top of the page). The
function seems to be finding the SWF id, but it's not playing.
Ultimately, I need to transfer the function to a page where the SWF
id (object) has been embedded with SWFObject 2.0. But until I can get
past this hurdle, I can't go anywhere. I must be missing something
rather basic here.

Any help would be appreciated.

I'm not sure if this is related to your problem, but:

1) You have an "ALIGN" attribute without value

2) EMBED is no valid XHTML and useless here anyway - just omit it

3) You should not use "javascript:" in your links - better:

<a href="#" onclick="document.swfmovie.Play();return false;">...
<a href="#" onclick="document.swfmovie.StopPlay();return false;">...
 
B

Bjoern Hoehrmann

* nola_dirigent wrote in comp.lang.javascript:
function movie() {
var findMovie = document.getElementById('swfmovie');
if (findMovie){
findMovie.play();
<a href="javascript:document.swfmovie.Play()"> [...]

One time you are using document.getElementById('swfmovie') and lower-
case "play", the other time you use "document.swfmovie" and "Play" in-
stead.
 
L

Lasse Reichstein Nielsen

nola_dirigent said:
if (findMovie){
findMovie.play();

lower-case "play" which doesn't work.
....
<a href="javascript:document.swfmovie.Play()"><font face="Arial">►</font>play&nbsp; </a>&nbsp;&nbsp; <font face="Arial">

Upper-case "Play" which does work. My bet is that's the correct spelling.
/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
lower-case "play" which doesn't work.
...

Upper-case "Play" which does work. My bet is that's the correct spelling.

A possibility, but one also has to consider the possibility that different
referencing makes the difference here instead. In the first instance the
object reference (stored in the `findMovie' variable) is retrieved
essentially with

document.getElementById("swfmovie")

while in the second instance it is retrieved with

document.swfmovie

Notice that the former is standards-compliant, the latter proprietary
referencing (which is a more error-prone shortcut version of the proprietary
document.embeds['swfmovie']; that (other invalid markup aside [0]) there is
a standards-compliant `object' element with an *ID* of `swfmovie', *and*
there is a proprietary EMBED element with the *same* *name* in the *same*
document.

This is a bad idea for at least three reasons: One, the element and
referencing is proprietary, thus inevitably more error-prone. Two, `id' and
`name' attribute values used for anchor names share the same namespace in
HTML, i. e. two different elements SHOULD NOT/MUST NOT have the same name/ID
[1]. Three, document.getElementById() also returns references to elements
which match case-insensitively the argument value in MSHTML, e. g. in
Internet Explorer (but not in version 8.0 and later unless in IE 7
Document/Compatibility Mode [2]); the OP did not state their runtime
environment (mentioning "javascript" [sic!] is worthless [3]), therefore we
cannot exclude that possibility.

So a possibility is here that the EMBED element object provides a `play'
method (that can be referred to with either character case, a possibility
known for MSHTML host object methods) that the `object' element object is
lacking [4,5].


PointedEars
___________
[0] <http://validator.w3.org/>
[1] <http://www.w3.org/TR/html401/struct/global.html#adef-id>
[2] <http://msdn.microsoft.com/en-us/library/ms536437(VS.85).aspx>
[3] <http://PointedEars.de/es-matrix>
[4] [de] <http://de.selfhtml.org/javascript/objekte/embeds.htm#play>
[5] <https://bugzilla.mozilla.org/show_bug.cgi?id=344830>
 
D

dhtml

nola_dirigent, 2011-10-09 05:47:

Please adjust your line breaks - your lines are *way* too long. Don't
use lines much longer than 70-80 characters - thank you!




I'm not sure if this is related to your problem, but:
All bets are off.
1) You have an "ALIGN" attribute without value

2) EMBED is no valid XHTML and useless here anyway - just omit it

3) You should not use "javascript:" in your links - better:

There is an FAQ Entry on that, somewhere, on a server that is usually
down.

Also several mentions of how valid HTML should be used (and not
XHTML).

The problem with document.xxx in mentioned in a "notes" article:
http://jibbering.com/faq/names/

http://jibbering.com/faq/names/extra_props_document.html

That article is mis-referenced by the FAQ, which links to
jibbering.com/names/ (missing /faq).
 
N

nola_dirigent

lower-case "play" which doesn't work.
...
Upper-case "Play" which does work. My bet is that's the correct spelling.

A possibility, but one also has to consider the possibility that different
referencing makes the difference here instead.  In the first instance the
object reference (stored in the `findMovie' variable) is retrieved
essentially with

  document.getElementById("swfmovie")

while in the second instance it is retrieved with

  document.swfmovie

Notice that the former is standards-compliant, the latter proprietary
referencing (which is a more error-prone shortcut version of the proprietary
document.embeds['swfmovie']; that (other invalid markup aside [0]) there is
a standards-compliant `object' element with an *ID* of `swfmovie', *and*
there is a proprietary EMBED element with the *same* *name* in the *same*
document.

This is a bad idea for at least three reasons: One, the element and
referencing is proprietary, thus inevitably more error-prone.  Two, `id' and
`name' attribute values used for anchor names share the same namespace in
HTML, i. e. two different elements SHOULD NOT/MUST NOT have the same name/ID
[1].  Three, document.getElementById() also returns references to elements
which match case-insensitively the argument value in MSHTML, e. g. in
Internet Explorer (but not in version 8.0 and later unless in IE 7
Document/Compatibility Mode [2]); the OP did not state their runtime
environment (mentioning "javascript" [sic!] is worthless [3]), therefore we
cannot exclude that possibility.

So a possibility is here that the EMBED element object provides a `play'
method (that can be referred to with either character case, a possibility
known for MSHTML host object methods) that the `object' element object is
lacking [4,5].

PointedEars
___________
[0] <http://validator.w3.org/>
[1] <http://www.w3.org/TR/html401/struct/global.html#adef-id>
[2] <http://msdn.microsoft.com/en-us/library/ms536437(VS.85).aspx>
[3] <http://PointedEars.de/es-matrix>
[4] [de] <http://de.selfhtml.org/javascript/objekte/embeds.htm#play>
[5] <https://bugzilla.mozilla.org/show_bug.cgi?id=344830>
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


PointedEars,

Thanks for your reply. Here is standards compliant HTML of the
problem I'm having. Just can't get the 'onclick' to fire the object.
It seems
I'm missing something basic.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>

<script src="scripts/swfobject_modified.js" type="text/javascript"></
script>
<script type="text/javascript">

function movie() {
var findMovie = swfObject.getObjectById('FlashID');
if (findMovie){
findMovie.Play();
} else {
alert ("Movie not found");
}
}
</script>
</head>
<body>



<object id="FlashID" classid="clsid:D27CDB6E-
AE6D-11cf-96B8-444553540000" width="300" height="200">
<param name="movie" value="correct.swf" />
<param name="quality" value="high" />
<param name= "play" value="false" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="6.0.65.0" />
<!-- This param tag prompts users with Flash Player 6.0 r65 and
higher to download the latest version of Flash Player.
Delete it if you don’t want users to see the prompt. -->
<param name="expressinstall" value="scripts/expressInstall.swf" />
<!-- Next object tag is for non-IE browsers. So hide it from IE
using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="correct.swf"
width="300" height="200">
<!--<![endif]-->
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name= "play" value="false" />

<!-- The browser displays the following alternative content for
users with Flash Player 6.0 and older. -->
<div>
<h4>Content on this page requires a newer version of Adobe
Flash Player.</h4>
<p><a href="http://www.adobe.com/go/getflashplayer"><img
src="http://www.adobe.com/images/shared/download_buttons/
get_flash_player.gif"
alt="Get Adobe Flash player" width="112" height="33" /></
a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</p>
<script type="text/javascript">
swfobject.registerObject("FlashID");
</script>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top