正确使用的addChild的正确、addChild

2023-09-08 13:35:17 作者:活得就像个孤独患者

我是新来的编码和AS3。我在读有关使用AS3中添加的东西在舞台上,并了解了的addChild方法。读我越发现,有不同的方式来使用它。我也看过一些方法是比别人好,而且某些方面并不擅长的一切,最好避免。

I'm new to coding and AS3. I was reading about adding things to the stage using AS3 and learned about the addChild method. Reading more I found that there are different ways to use it. I also read that some ways are better than others, and that some ways are not good at all and better avoided.

我不相信这些来源虽然。作为一个编码新手,我来寻求帮助,计算器。我即将启动的addChild重的项目,我想用正确的实施启动它。我相信你,所以让我问你:什么是正确使用的addChild的

I don't trust those sources though. As a coding newbie I come asking for help, StackOverflow. I'm about to start an addChild heavy project and I want to start it with the right implementations. I trust you, so let me ask you this: What's the correct use of addChild?

我只是想的东西添加到舞台,但我看,这不是很好的直接添加到舞台(没有进一步的说法虽然)。

I just want to add things to the stage, but I read that it's not good to add them directly to the stage (without further argument though).

stage.addChild()
this.addChild()
addChild()

是否还有其他方法吗?哪一个我应该使用?

Are there other ways? Which one should I use?

感谢您的时间。 :)

推荐答案

至于在显示列表层次结构的所有显示对象的顶级容器,只有一个的 舞台 不管有多少SWF文件加载到运行时。所以,一般情况下,对象不应该被添加到舞台上,直接,在所有。舞台应该包含的唯一对象是根对象。

As the top-level container for all display objects in the display list hierarchy, there is only one Stage no matter how many SWF files are loaded into the runtime. So, generally, objects should not be added to the Stage, directly, at all. The only object the Stage should contain is the root object.

通常情况下,你不应该使用: stage.addChild()

Generally, you should not use: stage.addChild()

添加 的DisplayObject 到显示列表应的 的DisplayObjectContainer

每个SWF文件都有一个关联的ActionScript类,称为主类延伸的显示对象的SWF文件。从这个类或层次结构中的任何的孩子,你可以叫 的addChild()

Each SWF file has an associated ActionScript class, known as the main class of the SWF file which extends a display object. From this class or any child within the hierarchy you may call addChild().

以下是相等的,并且将增加一个子当前显示对象容器的范围之内。

The following are equal, and would add a child within the scope of the current display object container.

this.addChild()
addChild()

关键字明确地定义范围;然而,当不放过一般是隐含的。

The this keyword explicity defines scope; however, is generally implicit when left off.

当通过的addChild()增加了一个显示对象被添加到所有其他孩子的前(上),给孩子添加到特定索引位置,使用 addChildAt() 的方法。

While a display object added via addChild() is added to the front (top) of all other children, to add a child to a specific index position, use the addChildAt() method.

参考文献:

显示编程 显示编程的基础知识 添加显示对象在显示列表 Display Programming Basics of display programming Adding display objects to the display list