Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Location
    Kamakura, Japan
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Substituting getElementById for document.all

    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.

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    728
    Thanks
    35
    Thanked 132 Times in 123 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Location
    Kamakura, Japan
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New to the CF scene
    Join Date
    Aug 2008
    Location
    Kamakura, Japan
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Substituting getElementById for all instances of document.all, and setAttribute for Flashvars, gave the following:

    [code}
    var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
    function swf_player_DoFSCommand(command, args) {
    var swf_playerObj = isInternetExplorer ? document.getElementById[tt1].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)
    [/code]

    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...

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    Quote Originally Posted by kamprint View Post
    with Javascript using the getElementById term:
    getElementById is a “method” for terminology’s sake.

    Quote Originally Posted by kamprint View Post
    Code:
    {
    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.

    Code:
    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>.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •