Hi Folks…
Posted this in another forum too. I have this set of codes for a simple chat program using SharedObjects. When I run the program, I type my name into the ‘chatName’ box and my message in the 'textInput’box. However when click on the ‘Send’ button or press the Enter key, I am getting the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at TextChat/sendMsg()
As mentioned in the error message I looked at the ‘sendMsg()’ function. I realised the problem was comming from the line :
text_so.setProperty ("msg",chatName.text +": "+ textInput.text);
I am wondering how ‘text_so’ can be a null object reference. It was already instantantiated and setup earlier in the code. I hope someone can shed light on this. The relevant lines of code are below. Thanks guys.
Setting up of the shared object function
private function doSO (e:NetStatusEvent):void
{
good=e.info.code == "NetConnection.Connect.Success";
if (good)
{
//Set up shared object
text_so=SharedObject.getRemote("test",nc.uri,false);
text_so.connect (nc);
text_so.addEventListener (SyncEvent.SYNC,checkSO);
}
}
The ‘sendMsg’ function
private function sendMsg (e:MouseEvent):void
{
noName=(chatName.text=="<Enter Name>" || chatName.text=="");
if (noName)
{
textArea.appendText ("You must enter your name
");
}
else
{
text_so.setProperty ("msg",chatName.text +": "+ textInput.text);
textArea.appendText (chatName.text +": "+textInput.text + "
");
textInput.text="";
}
}