title: Changing a Flash Video with Javascript
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2830944/change-flash-src-with-jquery">Change flash src with jquery?</a>  </p>
  </blockquote>
  
  
  
  <p><strong>EDIT</strong> <em>I figured out the first issue (not loading at all) so I took that portion out</em></p>
  
  <p>I have a flashplayer that I make like so:</p>
  
  <pre><code>&lt;div id="video_content"&gt;&lt;div id="flash_wrapper"&gt;
                  &lt;object classid="MyID" width="402" height="285" id="videoplayer" align="middle"&gt;
                      &lt;param name="movie" value="videoplayer.swf" /&gt;
                      &lt;param name="quality" value="high" /&gt;
                      &lt;param name="bgcolor" value="#000000" /&gt;
                      &lt;param name="play" value="true" /&gt;
                      &lt;param name="loop" value="true" /&gt;
                      &lt;param name="wmode" value="window" /&gt;
                      &lt;param name="scale" value="showall" /&gt;
                      &lt;param name="menu" value="true" /&gt;
                      &lt;param name="devicefont" value="false" /&gt;
                      &lt;param name="salign" value="" /&gt;
                      &lt;param name="allowScriptAccess" value="sameDomain" /&gt;
                      &lt;param name="allowFullScreen" value="true" /&gt;
                      &lt;param name="FlashVars" value="screencast_url=myVideo.flv" id="flash" /&gt;
                      &lt;!--[if !IE]&gt;--&gt;
                      &lt;object type="application/x-shockwave-flash" data="videoplayer.swf" width="402" height="285"&gt;
                          &lt;param name="movie" value="videoplayer.swf" /&gt;
                          &lt;param name="quality" value="high" /&gt;
                          &lt;param name="bgcolor" value="#000000" /&gt;
                          &lt;param name="play" value="true" /&gt;
                          &lt;param name="loop" value="true" /&gt;
                          &lt;param name="wmode" value="window" /&gt;
                          &lt;param name="scale" value="showall" /&gt;
                          &lt;param name="menu" value="true" /&gt;
                          &lt;param name="devicefont" value="false" /&gt;
                          &lt;param name="salign" value="" /&gt;
                          &lt;param name="allowScriptAccess" value="sameDomain" /&gt;
                          &lt;param name="allowFullScreen" value="true" /&gt;
                          &lt;param name="FlashVars" value="screencast_url=myVideo.flv" id="flash" /&gt;
  
                      &lt;!--&lt;![endif]--&gt;
                          &lt;a href="http://www.adobe.com/go/getflash"&gt;
                              &lt;img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /&gt;
                          &lt;/a&gt;
                      &lt;!--[if !IE]&gt;--&gt;
                      &lt;/object&gt;
                      &lt;!--&lt;![endif]--&gt;
                  &lt;/object&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>I have buttons that I want to use to change the video playing. The js method to change videos looks like this:</p>
  
  <pre><code>function ChangeVideo(videoIndex) {
  
  //Video Location String
  var vidLocation = "screencast_url=";
  
  //Determines what video to load
  switch (videoIndex) {
      case 1:
          //Change Video Location
          vidLocation += "myVideo.flv";
          break;
      case 2:
          //Change Video Location
          vidLocation += "myVideo2.flv";
          break;
      case 3:
          //Change Video Location
          vidLocation += "myVideo3.flv";
          break;
      case 4:
          //Change Video Location
          vidLocation += "myVideo4.flv";
          break;
  }
  
  //Change value of flashplayer FlashVar
  $('#flash').val(vidLocation);
  }
  </code></pre>
  
  <p>The video looks to have loaded correctly and all the information seems to be correct, but the video will not play when I hit the play button (Current video keeps playing).</p>
  
  <p>How would you load another video into a flash player after it has been loaded?</p>
  
  <p><strong>EDIT2</strong> If I try this:</p>
  
  <pre><code>//Creates empty values
  var flashvars = vidLocation;
  var params = {};
  var attributes = {};
  
  //Change video
  swfobject.embedSWF("videoplayer.swf", "video_content", "300", "120", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
  </code></pre>
  
  <p>Instead of :</p>
  
  <pre><code>//Change value of flashplayer FlashVar
  $('#flash').val(vidLocation);
  </code></pre>
  
  <p>Which seems to reload the player now, but it still does not play.</p>