如何在 AS3 的特定层(z 顺序)中 insert/place 库中的影片剪辑?

How to insert/place a movie clip from the library in a specific layer (z-order) in AS3?

我还没有找到任何相关信息,这让我很感兴趣。这是一个例子:

var example1:example1_mc = new example1_mc();
addChild(example1);

它出现在我场景中所有图层的顶部,我想将它分配到后面。

要将某项放在 parent 的最后 z-index,请执行以下操作:

addChildAt(example1,0);  

//the second parameter is the z-index to put the child at
//0 is the back, parent.numChildren-1 is the front most

//so this:
addChild(example1);

//is the same as this:
addChildAt(example1, numChildren-1);

addChild 始终将 child 放在前面。

以后要更改项目的位置,您可以再次 addChild/addChildAt,或使用 setChildIndex(example1,0)

所以这个:

addChildAt(example1,0); //add it to the back
setChildIndex(example1,2); //move it above the next 2 items 

与此完全*相同:

addChildAt(example1,0);
addChildAt(example1,2); //since example1 is already added, this just moves it above the next 2 items in the parent (it doesn't add a copy)

addChild 将在您添加了 child 的项目上发送一个 Event.ADDED 事件。 setChildIndex 不会导致事件被分派。