我试图创建一个非常基本的flash游戏,使用Tom Krcha的P2P游戏库,我在这里发现,我唯一的问题是当我试图实现类,我得到一个错误,当我尝试启动应用程序,
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Logger$/log()[C:_DEVP2PGameEnginesrcLogger.as:20]
at P2PGame/onConnect()[C:_DEVP2PGameEnginesrcP2PGame.as:54]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at com.adobe.fms::P2PSession/onNetGroupConnect()[C:_DEVP2PMessengerLibsrccomadobefmsP2PSession.as:208]
at com.adobe.fms::P2PSession/netStatus()[C:_DEVP2PMessengerLibsrccomadobefmsP2PSession.as:312]
这是我的Flash Builder代码,
<?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>
你知道为什么会这样吗?我已经包含了库,但我仍然得到那个错误,有什么想法吗?
提前感谢!
在Logger类的log()函数中抛出错误消息。
只有一个TextField,它的属性正在被访问,所以这可能是罪魁祸首(txtArea
在某种程度上是null
)。奇怪的是,在源代码中有一个if语句,它应该防止这种错误(if (txtArea != null)
)。你用的是旧版本吗?你可能应该从github下载源代码,看看当前版本是否仍然抛出相同的错误。
编辑
我刚刚用SWC包创建了一个小测试:
package
{
import flash.display.Sprite;
public class Test extends Sprite
{
public function Test ()
{
Logger.log ("something");
}
}
}
运行它,然后:
TypeError: Error #1009: Cannot access a property or method of a null object reference。记录器/log()美元在测试()
而对于来自github的源版本,一切都运行良好(尽管不做任何事情)。