AS3 - Getting a child by name and then by depth

I have 3 sprites: img1spr, img2spr and img3spr. Inside each sprite there are several bitmap images. Each sprite has a name:

img1spr.name=name1;
img2spr.name=name2;
img3spr.name=name3;

Now the names change every time the function executes and what I want to know is there a way to do something like:

getChildByName("name1").getChildAt(0)

This means that I want to find a sprite with the name name1, and then find the first child element in it, or, otherwise, count the number of elements inside name1 with numChildren.

Is there any way to do this?

+3
source share
1 answer

You are almost there - getChildByNamereturns a DisplayObject, and you must send it in DisplayObjectContainerto call getChildByNameandnumChildren

trace(DisplayObjectContainer(getChildByName("name1")).numChildren);
DisplayObjectContainer(getChildByName("name1")).getChildAt(0);

, , ( flash). , getChildByName - , .

+4

Source: https://habr.com/ru/post/1722692/


All Articles