"null" is null or not an object

Discussion in 'JavaScript' started by nickjason, Nov 17, 2009.

  1. #1
    I am using AS2 with javascript interactions. Could anyone help me with this:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Actionscript Javascript Communication from Circlecube</title>
    
    <script src="swfobject.js" type="text/javascript"></script>
    		<script type="text/javascript">
    		swfobject.registerObject("myId", "9.0.0", "expressInstall.swf");
    		
    function recieveTextFromFlash(Txt) {
    
    	document.getElementById('htmlText').value = Txt;
    
    }
    
    </script>
    
    </head>
    
    
    
    <body>
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    
      <tr>
    
        <td width="400"><h1>From <a href="http://blog.circlecube.com">CircleCube.Com</a></h1> 
    
          <div align="center">Actionscript Javascript
    
          Communication</div>
    
          <form id="form1" name="form1" method="post" action="">
    
          <textarea name="htmlText" id="htmlText" cols="50" rows="15"> </textarea>
    
          <br />
    
          <input type="button" name="sendToFlash" id="sendToFlash" value="Send Text To Flash" 
    
    onclick="getElementById('myId').sendTextFromHtml(htmlText.value); 
    
    document.getElementById('htmlText').value = ''" />
    
        </form>
    
          Return to the post: <br />
    
          <a 
    
    href="http://blog.circlecube.com/2008/02/01/actionscript-javascript-communication/">http://blog.ci
    
    rclecube.com/2008/02/01/actionscript-javascript-communication/</a></td>
    
        <td>
    
        
    
    
    
    
    
    
    
    
    
        <div align="left" id="swf">
    
        <object id="flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="300" 
    
    height="120">
    				<param name="flash" value="test.swf" />
            		<!--[if !IE]>-->
    				<object type="application/x-shockwave-flash" 
    
    data="test.swf" width="300" height="120" id="flash">
    				<!--<![endif]-->
    				<div>
    					<h1>Alternative content</h1>
    					<p><a 
    
    href="http://www.adobe.com/go/getflashplayer"><img 
    
    src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe 
    
    Flash player" /></a></p>
    				</div>
    				<!--[if !IE]>-->
    				</object>
    				<!--<![endif]-->
    			</object>
    
        </div></td>
    
      </tr>
    
    </table>
    
    
    
    </body>
    
    </html>
    Code (markup):
    Im stucked with the 'null' is null or not an object problem. IE and FF.
     
    nickjason, Nov 17, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Where is the error occurring?
    We may need to see the code for swfobject.js
     
    camjohnson95, Nov 17, 2009 IP
  3. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #3
    the error is likely to be with getElementById('myId') or htmlText

    what makes myId? is that the id of the script?

    try checking to see if myId is available first

    also, where do you set htmlText as an object?

    
    var communicateFlash = function(whatid) {
        var targetObject = document.getElementById(whatid);
        if (!targetObject) {
            alert("something is wrong, can't find " +whatid+ " in the DOM");
            return;
        }
       
        try {
            targetObject.sendTextFromHtml(document.getElementById("htmlText").value); // reference field correctly in DOM!  
        }
        catch(e) {
            alert("could not complete sending...");
        }
    };
    
    document.getElementById("sendToFlash").onclick = function() {
        communicateFlash("myId");
    };
    
    Code (javascript):
    remove the inline onclick= on the button element. this ought to work or at least give you an indication as to what's failing, the flash embed or the reading of data. for sure, sendTextFromHtml(htmlText.value) is wrong.
     
    dimitar christoff, Nov 18, 2009 IP
  4. gacba

    gacba Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Welcome to the #1 most requested error in JavaScript. :)

    May I suggest using something like Firebug for Firefox to debug this stuff? You'll get far better information than the ugly default error...
     
    gacba, Nov 20, 2009 IP