views:

260

answers:

3

I have a very simple flash program that plays music. It consists of a play pause button and a timer that shows the current position of the song. I'm trying to make it possible to pause or play the song using a regular form button.

<div class="musicplayer_playpause">
            <script type="text/javascript">
            AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','65','height','68','src','player','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','transparent','id','flashobject','movie','player','flashvars','id=&lt;?=$cur_songid;?&gt;&amp;type=&lt;?=$_GET["type"];?&gt;&amp;csid=&lt;?=$cur_songid;?&gt;&amp;l=&lt;?=$Arrcntt+1;?&gt;"' ); //end AC code
            </script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" id="flashobject" width="65" height="68">
              <param name="movie" value="player.swf" allowscriptaccess="always"/>
              <param name="quality" value="high" />
              <param name="wmode" value="transparent" />
        <param name="id" value="flashobject" />
        <param name="swliveconnect" value="true" />
              <embed src="player.swf" name="flashobject" width="65" height="68" quality="high" allowscriptaccess="always" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" wmode="transparent" swliveconnect="true" ></embed>
          </object>
          </noscript></div>

Here's the Javascript function, which I put in the section:

<script type="text/javascript">
function Pause() {
var flash =  document.getElementById('flashobject');
flash.PlayPause;
}
</script>

And finally here's the button I'm using:

<form>
<input type="button" value="Play" name="Play" onClick="Pause();"> 
</form>

When I click the button, Firefox's error console says "Flash is null" What am I doing wrong?

+1  A: 

The script tag containing Pause is malformed. Add a trailing quote to the type attribute.

Additionally, AC_FL_RunContent is not defining an id for the movie. Add 4 more params to it - 'id', 'flashobject', 'name', 'flashobject'.

AC_FL_RunContent is described in this Adobe technote http://kb2.adobe.com/cps/127/tn_12701.html, which says this:

  • id (attribute for object, object only)
    Movie Identifier. Identifies the Flash movie to the host environment (a web browser, for example) so that it can be referenced using a scripting language.
  • name (embed only) Movie name. Identifies the Flash movie to the host environment (a web browser, typically) so that it can be referenced using a scripting language such as JavaScript or VBScript.
Lachlan Roche
Thanks! But now I'm getting "flash is null." I could really use some help on this.
John D
Added tags to AC_FL_Runcontent but I'm still getting "flash is null"
John D
Made all of those changes (see edits above) but still getting "flash is null."
John D
The params you're suggesting I add to AC_FL_RunContent actually belong under object and embed, respectively. I already had them there. I added them to AC_FL_RunContent anyway, but I'm still getting the same error.
John D
+1  A: 

I don't think it's a direct solution to your problem, but I know from experience that using

var flash =  document.getElementById('flashobject');
flash.PlayPause;

will not show the same behaviour in all popular browsers. you can try to use the following function to return the object:

function thisMovie(movieName) {
  if(navigator.appName.indexOf("Microsoft") != -1) {
    return window[movieName];
  } else {
    return document[movieName];
  }
};
thisMovie('flashobject').PlayPause();

If you are using jQuery however, the following will do:

$("#flashobject")[0].PlayPause();

edit: I found a more updated version of the thisMovie function. I would still recommend the jQuery way though :)

function getFlashMovieObject(movieName){
  if(document.embeds[movieName])
    return document.embeds[movieName];
  if(window.document[movieName])
    return window.document[movieName];
  if(window[movieName])
    return window[movieName];
  if(document[movieName])
    return document[movieName];
  return null;
}
Jasper De Bruijn
I'm getting back "thisMovie('flashobject') is undefined" when the button is clicked.
John D
A: 

find this: <param name="movie" value="player.swf" allowscriptaccess="always"/> replace with

 <param name="movie" value="player.swf" />
   <param name="allowScriptAccess" value="always" />

I would still use Jasper's function

michael