2013-05-12 88 views
0

我想刪除名爲'_pokemon'的對象。如果被雨打落十次,稱爲'_jednaLinia'(意思是'_oneLine'),它應該被移除。我確實使用了這個代碼,是的,它做了我的_pokemon消失的工作,但它仍然在handleColisin函數中被檢測到。而主類仍然不斷提及它,因爲我得到了口袋妖怪類此錯誤「錯誤#1009:無法訪問空對象引用的屬性或方法hittest,removechild,不可見對象保持問題,閃存,as3


我不幹新AS3和嘗試了許多簡單的解決方案,但似乎沒有工作,我打算如何。 如果可能請回答。

## some code I think is necessary, not all of it 
... 
public class Main extends Sprite 
{ 

    private var _pokemon:Pokemon;  
    public function Main():void 
    { 
     _starTimer = new Timer(30); 
     addEventListener(Event.ADDED_TO_STAGE, init); 
     _starTimer.addEventListener(TimerEvent.TIMER, start); 

    } 
    private function init(e:Event = null):void 
    { 
     removeEventListener(Event.ADDED_TO_STAGE, init);  
     _starTimer.start(); 
     this.addChild(_pokemon); 

    } 




...and further... 

    private function _pokemonLive(e:Event = null):void 
    {   
     decreaseLive--;   
     if (decreaseLive == 0) 
     {    
      _pokemon.parent.removeChild(_pokemon);/i think i tried all methods 
      _starTimer.stop(); 
     } 
    } 

而且就像我剛纔提到的。口袋妖怪課上有錯誤,它上面有隨機移動功能。這是1009錯誤的地方。如有需要,我發送更多的代碼。

+0

當你叫_pokemonLive?它是一個事件監聽器嗎? – 2013-05-12 16:35:56

+0

這部分激活_pokemonLive的代碼位於privat函數中,該函數使用timeEvent監聽器調用,並命名爲「start」'code'.................. if(_pokemon。 hitTestObject(_linia [COUNT])) \t \t \t { \t \t \t handleCollision(_linia [COUNT]); \t \t \t \t _pokemonLive(); \t \t \t \t \t \t} – derkarol 2013-05-12 19:55:55

+0

看看我的答案,它應該工作,然後接受它。 – 2013-05-12 21:05:09

回答

0

將'dead'布爾值添加到您的'Main'類。

變化

private function _pokemonLive(e:Event = null):void 
    {   
     decreaseLive--;      
      _pokemon.parent.removeChild(_pokemon); 
      _starTimer.stop(); 
    } 

private function _pokemonLive(e:Event = null):void 
    {   
     if(dead == false) 
     {  
     decreaseLive --; 
     if (decreaseLive == 0) 
     {    
      dead = true; 
      _pokemon.parent.removeChild(_pokemon);/i think i tried all methods 
      _starTimer.stop(); 
     } 
     } 
    } 
+0

Thx沒有嘗試這種方式。所以我會試試看。我們將會看到。 – derkarol 2013-05-12 19:17:06

+0

Nah,不工作。我會用布爾邏輯玩一下,看看我能完成什麼,但我不確定是否是這樣。 TY負擔得起。 – derkarol 2013-05-12 19:33:05

+0

@derkarol如果pokemon已被刪除,則不能調用removeChild(_pokemon)。你是否收到我的代碼錯誤?如果是這樣,什麼? – 2013-05-12 21:06:14