【发布时间】: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