views:

11

answers:

1

Hi everybody !

For instance the mx.controls.Image objects are only displayed when i add them directly to the main application object. If i add a "subimage" to the previously created Image object it simply doesnt show. Why ? What concept did i miss ?

What I want to do:

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

OK, and here the code how it by directly adding the subimg to the Application just like img - this one works ofcourse:

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
A: 

What exactly is it that you want to do, that the second example isn't doing for you? Generally speaking UIComponents are things with complicated internals, being that they're skinnable and styleable and so on, and they manage their own contents (as with Image, which populates itself with loaded assets).

I'm not familiar enough with Image to say precisely what the problem is - whether the subimg object is being hidden or whether the load is failing, or what. But what you should probably do is to make your own Sprite and add both Images inside it, or make two sprites, add an image to each, and parent them the way you like, so you can have a similar parent-child relationship without mucking around in the internals of a component.

For example:

// ... 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);
fenomas