[英]P2P Flash game #1009 error
我正在嘗試使用湯姆·克爾查(Tom Krcha)的P2P游戲庫創建一個非常基本的Flash游戲,我在這里找到了它 ,唯一的問題是當我嘗試實現該類時,在嘗試啟動該應用程序時出現錯誤,
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]
這是我的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:錯誤#1009:無法訪問空對象引用的屬性或方法。 在Logger $ / log()在Test()
而使用github的源版本,一切運行正常(盡管什么也沒做)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.