2013-05-12 85 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