I am trying to create a very basic flash game, using Tom Krcha's P2P gaming library, which I found here, the only problem I have is when I try to implement the class, I get a error when I try to launch the app,
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Logger$/log()[C:\_DEV\P2PGameEngine\src\Logger.as:20]
at P2PGame/onConnect()[C:\_DEV\P2PGameEngine\src\P2PGame.as:54]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.adobe.fms::P2PSession/onNetGroupConnect()[C:\_DEV\P2PMessengerLib\src\com\adobe\fms\P2PSession.as:208]
at com.adobe.fms::P2PSession/netStatus()[C:\_DEV\P2PMessengerLib\src\com\adobe\fms\P2PSession.as:312]
here is my Flash Builder code,
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="520" height="391"
applicationComplete="init()">
<fx:Script>
<![CDATA[
private var game:P2PGame;
private const SERVER:String = "rtmfp://p2p.rtmfp.net/";
private const DEVKEY:String = "DEV_KEY_HERE";
protected function init():void
{
var usr:String = "user"+(Math.round(Math.random()*1000));
game = new P2PGame(SERVER+DEVKEY,"my_group");
game.addEventListener(Event.CONNECT, onGameConnect);
game.connect(usr);
}
private function onGameConnect(event:Event):void{
main_log.text += "P2P connection successfull..."
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextArea id="main_users" x="346" y="10" width="164" height="371" color="#FFFFFF"
contentBackgroundColor="#000000" text="ACTIVE USERS" textAlign="center"
textDecoration="underline" verticalAlign="top"/>
<s:TextArea id="main_log" x="10" y="10" width="328" height="371"/>
</s:WindowedApplication>
any idea why this could be happening? I have included the libraries, and yet I still get that error, any ideas?
Thanks in advance!
The error message is thrown in the log() function of the Logger class.
There is nothing else but a TextField, whose properties are being accessed, so this is probably the culprit (txtArea
is null
at some point). Strangely enough, there is an if statement in the source code, which should prevent this kind of error (if (txtArea != null)
). Could you be working with an older version? You should probably download the source code from github and see if the current version still throws the same error.
EDIT
I just created a little test with the SWC package:
package
{
import flash.display.Sprite;
public class Test extends Sprite
{
public function Test ()
{
Logger.log ("something");
}
}
}
Run it, and voilà:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Logger$/log() at Test()
Whereas with the source version from github, everything runs fine (though doesn't do anything).