4 Replies Latest reply on Jul 26, 2011 10:52 PM by relaxatraja

    Set the bgcolor attribute value

    Black-horse

      Hi,

       

      The following doesn't work:

       

       

       

      But if you change setAttribute to ("width", "800"), it works with no problem! What am I missing? Is there an alternative to setAttribute method?

       

      Many thanks in advance!

      Mike

        • 1. Re: Set the bgcolor attribute value
          robdillon Most Valuable Participant

          Whatever you pasted into the message to show what doesn't work, didn't work. In any case, to set the value of an object's property, you just specify the property and give it a value. e.g.  someObjectInstanceName.property = value, or, thisSymbol.width = 200.

           

          Is that what you were looking for?

          • 2. Re: Set the bgcolor attribute value
            Black-horse Level 1

            I don't know why my code didn't appear! Let me try again:

             

            <!DOCTYPE HTML>
            <title>Test</title>
            <embed id="foo" src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40" type="application/x-shockwave-flash" />
            
            <script type="text/javascript">
            document.getElementById("foo").setAttribute("bgcolor", "#00FF00");
            </script>

             

            All I want is set the bgcolor value dynamically using the setAttribute method or an alternative. I read your answer a few times, but didn't understand it. Would you mind explaining more and providing a snippet?

             

            Thanks!

            • 3. Re: Set the bgcolor attribute value
              robdillon Most Valuable Participant

              My answer, as it turns out, had nothing to do with your actual question. Are you trying to change the background color of the actual Flash movie, or the background color that shows up in the html before the Flash movie fullly loads? The <param name="bgcolor" value="#666633" />, for instance, in the Object tag for a Flash movie, is the background color for the space occupied by the Flash movie and not the background color OF the movie itself.

               

              While the parameters for the Object tag are settable using Javascript, I've only ever seen them set as part of a "document.write..." command in Javascript. I'm not sure that helps you though.

              • 4. Re: Set the bgcolor attribute value
                relaxatraja Level 5

                Have a look at this code:

                 

                <!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">
                <meta name="language" content="english">
                <meta http-equiv="Content-Style-Type" content="text/css">
                <meta http-equiv="Content-Script-Type" content="text/javascript">

                <title>rough example</title>

                <style type="text/css">
                #flash{
                    width:800px;
                    margin:auto;
                }
                </style>

                <script type="text/javascript">

                   var c,o,p0,p1;

                function init(){
                   c=document.getElementById('colors').value;

                document.getElementById('colors').onchange=function(){
                   document.getElementById('flash').removeChild(o);
                   c=this.value;
                   makeIt();
                }
                   makeIt();
                }

                function makeIt(){
                   o=document.createElement('object');
                   o.setAttribute('type','application/x-shockwave-flash');
                   o.setAttribute('data','http://rain-lover.webs.com/menu.swf');
                   o.setAttribute('width',800);
                   o.setAttribute('height',600);

                   p0=document.createElement('param');
                   p0.setAttribute('name','movie');
                   p0.setAttribute('value','http://rain-lover.webs.com/menu.swf');

                   p1=document.createElement('param');
                   p1.setAttribute('name','bgcolor');
                   p1.setAttribute('value',c);

                   o.appendChild(p0);
                   o.appendChild(p1);

                   document.getElementById('flash').appendChild(o);
                }

                   window.addEventListener?
                   window.addEventListener('load',init,false):
                   window.attachEvent('onload',init);
                </script>

                </head>
                <body>

                <div>
                <select id="colors">
                <option value="000000">black</option>
                <option value="ff0000">red</option>
                <option value="0000ff">blue</option>
                <option value="00ff00">green</option>
                <option value="ff9933">yellow</option>
                </select>
                </div>

                <div id="flash"></div>

                </body>
                </html>

                copy and paste and test it.