AS3:由数组项引用删除对象数组、对象

2023-09-08 15:34:48 作者:怕伤,就别爱

我想加些雪碧对象的为阵列的的内容,我希望能够清除他们从舞台。我会假设,如果有装载机参与,我需要做的。

I am trying to add some Sprite objects as the contents of an array, and I would like to be able to "clear" them from the stage. I would assume that if there are loaders involved, I need to do

_imgArray[i].close();
_imgArray[i].unload();

如果我使用的是精灵,我可以这样做:

And if I am using a sprite, I can do:

removeChild(_imgArray[i]);

以上都不工作。为什么???

None of the above work. WHY???

有关如何我设置此功能,请参阅乔尔的帖子这里 ......但是请注意,他并没有包括从视图中删除它们的参考。

For an example and/or description of how I am setting this up, see Joel's post here ...but note that he hasn't included a reference for deleting them from view.

目前我尝试:

for(i = 0; i < _localXML.length(); i++)
{
   var tmp:BMLink = new BMLink(_localXML[i], _bw, _bh, i);
   _imgArray[i] = tmp;
   _imgArray[i].x = (_bw + _mainpad) * i; 
   _base.addChild(_imgArray[i]);
}

但是,这并不正常工作。 我喜欢它,如果有人可以给我解释一下,为什么这不会是正确的语法。 被填充数组的类实例都延长精灵,但他们有自己的个性装载机里面瓦特/进度事件等。

But this doesn't work. I would love it if someone could explain to me why this wouldn't be proper syntax. The class instances that are populating the array are all extending sprite, but they have their own individual loaders inside w/ progress events etc.

JML

推荐答案

确定;我终于理解了它通过一组试验和错误。 看来,我试图消除我的主类精灵的孩子(这一点),而不是说我已经加入了孩子们的子精灵。

OK; I finally figured it out through a bunch of trial and error. It seems that I was attempting to remove the child of my main class sprite (this) rather than the sub-sprite that I had added the children to.

很抱歉的噪音,但备案,如果你发现你不能做

Sorry for the noise, but for the record, if you find that you can't do

this.removeChild(_imgArray[i]);

这不是因为你没有正确的语法,而是因为你可能没有一个

it's not because you don't have the correct syntax, but because you might not have an

_imgArray[i] 

在那个特定的显示列表层次结构的点...所以...

at that particular point of your display list hierarchy... so...

_base.removeChild(_imgArray[i]);

...工作在这种情况下

...worked in this case.

JML