【问题标题】:hittest, removechild,not visible object remain issue,flash ,as3hittest,removechild,不可见的对象仍然存在问题,flash,as3
【发布时间】:2013-05-12 16:25:44
【问题描述】:

我正在尝试删除名为“_pokemon”的对象。如果它被称为“_jednaLinia”(意为“_oneLine”)的雨水击中十次,则应将其移除。我确实使用了这段代码,是的,它完成了我的 _pokemon 确实消失的工作,但它仍然在 handleColisin 函数上被检测到。主类仍然引用它,因为我在口袋妖怪类上遇到了这个错误

错误 #1009:无法访问空对象引用的属性或方法。


我对 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();
        }
    }

就像我提到的那样。我在 Pokemon Class 上遇到错误,它具有随机移动功能。这就是错误 1009 显示的地方。如有必要,我会发送更多代码。

【问题讨论】:

  • 你什么时候打电话给_pokemonLive?它是一个事件监听器吗?
  • 激活 _pokemonLive 的这部分代码在使用 timeEvent 监听器调用的 privat 函数中,名为“start”`code'...... ... if ( _pokemon.hitTestObject(_linia[count]) ) { handleCollision(_linia[count]); _pokemonLive(); }
  • 看我的回答,应该可以,然后接受。

标签: actionscript-3 flash hittest removechild


【解决方案1】:

将“死”布尔值添加到“主”类。

改变

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();
        }
        }
    }

【讨论】:

  • Thx 没有尝试这种方式。所以我会试试看。我们会看到的。
  • 不,不工作。我会玩一下布尔值,看看我能完成什么,但我不确定这是否是正确的方法。 TY 无论如何都买得起。
  • @derkarol 如果 pokemon 已被删除,您将无法调用 removeChild(_pokemon)。您收到我的代码错误吗?如果有,是什么?
  • 同样的事情。这是有记忆的东西。它以某种方式将它保存在内存中,我还不知道。 #1009:无法访问空对象引用的属性或方法。但请记住,我在移动路径调用/设置期间不是在 Main 类上而是在 pokemon 类上得到这个错误。即使它已经被移除并且因为它。
猜你喜欢
  • 2015-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多