...

View Full Version : Substituting getElementById for document.all



kamprint
08-13-2008, 01:07 PM
For cross-browser-compatible viewing of a Flash video, I have tried to replace the following IE-only code:

<code>
{
document.all['fs_player'].FlashVars='movie_name='+tt1;
}
</code>

with Javascript using the getElementById term:

<code>
{
var FlashVars=document.getElementById["+tt1"].getAttribute("movie_name")
document.getElementById["*tt1"].setAttribute("movie_name","+tt1")
}
</code>

This is not correct, as anyone with Javascript experience would probably know. Lacking such experience, I don't know what's wrong, in particular how to identify the Id that getElement is supposed to get, which parts of the Javascript syntax are invariable and which parts may be modified, when to refer to or call the swf_player.swf and when to refer to or call the actual movie to be played.

The original Javascript code automatically generated by video-conversion software is apparently obsolete. The resulting video plays in IE but not in FF. The position-slider does not work in IE.

I have read all the relevant tutorials at javascriptkit.com, Adobe, various other sources, but these have not been specific enough to enable the writing of workable code for this particular application. It should be fairly simple (though beyond my capability so far) to place a video (swf or flv) at a website and have it viewable as similar ones are at numerous other sites, have the user controls work, be able to set whether it starts automatically or not, etc. Test pages are at www.kamprint.com/techviz.htm and www.kamprint.com/techviz2.htm. These are not linked to anything at the site because the video is not yet ready for prime time. I would appreciate any help, suggestions, pointers, advice, specific code, or whatever, so that I can spend some time on the actual content. Many thanks in advance and sorry if the coding problem is boring, maybe the site itself will make up for that.

mrhoo
08-13-2008, 04:28 PM
change document.getElementById["+tt1"] to document.getElementById[tt1],

and setAttribute("movie_name","+tt1") to setAttribute("movie_name",tt1)

tt1 is already a string, you are prefixing a literal '+' on the ids.

kamprint
08-14-2008, 09:01 AM
Thanks, I will try this and report the results here.

Sorry to trouble you with what appears to be an elementary syntax error, but that's how one starts. There will be more errors to follow, but we'll take them one at a time. I really do appreciate the help.

kamprint
08-16-2008, 03:25 AM
Substituting getElementById for all instances of document.all, and setAttribute for Flashvars, gave the following:


.swf_player : document.swf_player;
if(command=='error')
{alert("ERROR! "+args);}
}
function set_movie(tt1)
{
document.getElementById[tt1].setAttribute("movie_name",tt1)
}
function fs_play()
{
document.getElementById[tt1].setAttribute("player_command",play)
}
function fs_stop()
{
document.getElementById[tt1].setAttribute("player_command",stop)
}
function fs_color(tt1)
{
document.getElementById[tt1].setAttribute("player_color",tt1)


This example has swf_player instead of fs_player, but both produce the same error message: that the object of getElementById is either null or cannot be found. Fundamentally, I am confused about where to insert the name of the Flash player, and whether it should be called fs_player or swf_player (for a *.swf file), and where to insert the name of the actual movie (techviz.swf in this case). Also I have no idea what tt1 is. No doubt these are not the only confusions. The former code with document.all works, but only with IE, not with FF, and even in IE the slider does not work. With thanks...

Arbitrator
08-16-2008, 07:44 AM
with Javascript using the getElementById term:getElementById is a “method” for terminology’s sake.



{
var FlashVars=document.getElementById["+tt1"].getAttribute("movie_name")
document.getElementById["*tt1"].setAttribute("movie_name","+tt1")
}getElementById is followed by parentheses, not brackets. The code that you would use is shown below assuming that you mean to reference an HTML/XHTML object element with an id attribute value of fs_player.


document.getElementById("fs_player");

Appending and removing parameters to and from the FlashVars param element is a more difficult task that I won’t get into since I’m not sufficiently familiar with Flash.

Suffice it to say that you seem to be confusing parameters with HTML/XHTML attributes; for example, you’re using setAttribute to set a movie_name attribute that doesn’t exist. In other words, you’re creating something like <object … movie_name="tt1" player_command="play"></object> when you need to be creating something like <object …><param name="FlashVars" value="movie_name=tt1&#x26;player_command=play"></object>.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum