Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 9th, 2010, 10:27 AM
Registered User
Join Date: Feb 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default getElementbyId comes back Null?

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=<?=$cur_songid;?>&type=<?=$_GET["type"];?>&csid=<?=$cur_songid;?>&l=<?=$Arrcntt+1;?>"' ); //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>
Here's the Javascript function, which I put in the section:

<script type="text/javascript">
function Pause() {
var flash =  document.getElementById('flashobject');
And finally here's the button I'm using:

<input type="button" value="Play" name="Play" onClick="Pause();"> 
When I click the button, Firefox's error console says "Flash is null" What am I doing wrong?
Old February 9th, 2010, 12:35 PM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

Try this link about how Firefox differs from IE in this regard: Flash interaction with JavaScript. Basically you need to use the embeds collection.
Also your error message has 'Flash' with an uppercase 'F',are you sure your code is correct and uses lowercase 'flash'?

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript getElementById returns null VictorVictor ASP.NET 2.0 Professional 15 January 15th, 2010 06:53 PM
getElementById itHighway Javascript How-To 1 June 7th, 2009 04:40 AM
Using getElementById Frank Huddleston XML 4 November 11th, 2005 01:44 PM
setting date/time fields back to null value badgolfer Access 1 August 8th, 2005 02:29 AM
'getElementById()' anshul Javascript How-To 1 September 1st, 2004 03:57 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.