2011-11-17 142 views
0

我想創建一個非常基本的Flash遊戲,使用Tom Krcha的P2P遊戲庫,我發現here,我遇到的唯一問題是當我嘗試實現該類時,出現錯誤當我嘗試啓動應用程序,P2P Flash遊戲#1009錯誤

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> 

任何想法,爲什麼這可能發生?我已經包括了圖書館,但我仍然有這個錯誤,有什麼想法?

在此先感謝!

回答

1

錯誤消息拋出Logger class的log()函數中。

沒有別的,只有一個TextField,其屬性被訪問,所以這可能是罪魁禍首(txtAreanull在某些時候)。奇怪的是,源代碼中有一條if語句,它應該能夠防止這種錯誤(if (txtArea != null))。你可以使用舊版本嗎?你應該從github下載源代碼,看看當前版本是否仍然會拋出相同的錯誤。

編輯

我剛剛創建與SWC包一個小測試:

package 
{ 
    import flash.display.Sprite; 

    public class Test extends Sprite 
    { 
     public function Test() 
     { 
      Logger.log ("something"); 
     } 
    } 
} 

運行它,瞧:

類型錯誤:錯誤#1009:無法訪問屬性或空對象引用的方法。 () at Logger $/log() at Test()

儘管使用github的源代碼版本,但一切運行良好(儘管沒有做任何事情)。

+0

我剛剛剛剛下載了最新版本的庫。所以我懷疑它可能是... – Odyss3us

+0

是的,它是...看到我的編輯。 – weltraumpirat

+0

好東西,看起來就像是你說的'SWC',我下載並重新包含了庫項目文件,將版本更改爲'10.2.0',然後將其包含到我的項目的構建路徑中,成功了!謝謝您的幫助! – Odyss3us