Actionscript 3 闪存as3未显示图像或UIComponent的子级

Actionscript 3 闪存as3未显示图像或UIComponent的子级,actionscript-3,image,children,Actionscript 3,Image,Children,例如,仅当我将mx.controls.Image对象直接添加到主应用程序对象时,才会显示它们。如果我将“子图像”添加到先前创建的图像对象中,它就不会显示。为什么?我错过了什么概念 我想做的是: var img : Image = new Image; var subimg : Image = new Image; img.source = "images/panel.png"; subimg.source = "images/panel.png"; subimg.x = 10; subimg

例如,仅当我将mx.controls.Image对象直接添加到主应用程序对象时,才会显示它们。如果我将“子图像”添加到先前创建的图像对象中,它就不会显示。为什么?我错过了什么概念

我想做的是:

var img : Image = new Image;
var subimg : Image = new Image;

img.source = "images/panel.png";
subimg.source = "images/panel.png";

subimg.x = 10;
subimg.y = 10;
addChild (img);
img.addChild(subimg);    // img is displayed, but not the overlapping subimg
好的,这里的代码是如何通过直接将subimg添加到应用程序中的,就像img一样-这一个当然有效:

var img : Image = new Image;
var subimg : Image = new Image;

img.source = "images/panel.png";
subimg.source = "images/panel.png";

subimg.x = 10;
subimg.y = 10;
addChild (img);
addChild(subimg);    // img & subimg is displayed correctly

你到底想做什么,第二个例子不适合你?一般来说,UIComponents是具有复杂内部结构的东西,因为它们是可蒙皮和可样式化的,等等,并且它们管理自己的内容(与图像一样,图像用加载的资产填充自己)

我对图像不够熟悉,无法准确地说出问题是什么-是
subimg
对象被隐藏了,还是加载失败了,或者是什么。但您可能应该做的是制作自己的精灵,并在其中添加两个图像,或者制作两个精灵,为每个精灵添加一个图像,并以您喜欢的方式为其设置父对象,这样您就可以拥有类似的父子关系,而无需在组件的内部乱搞

例如:

// ... make img and subimg
var imgContainer:Sprite = new Sprite();
imgContainer.addChild(img);
var subimgContainer:Sprite = new Sprite();
subimgContainer.addChild(subimg);
imgContainer.addChild(subimgContainer);
addChild(imgContainer);