Correct use of addChild

拈花ヽ惹草 提交于 2019-12-04 14:05:04

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.

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

Adding a DisplayObject to the display list should be performed within the scope of a DisplayObjectContainer.

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.

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.

References:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!