Flash AS3 dynamically adds children. Problem with their name and calling each shared

I need to get access to each child after I dynamically add them to the scene, but I have problems figuring out how.

In a click, it adds an image to the scene, and I need to make them glow one at a time using the for () function, but I cannot figure out how to name them each with its own name (name + i) to access them later.

Thank you in advance

stage.addEventListener(MouseEvent.MOUSE_DOWN, clicky);
var i = 1; 
function clicky(event:MouseEvent):void
{
    i++;
    var fl_MyInstance:LibrarySymbol = new LibrarySymbol();
    addChild(fl_MyInstance);


    var myStageX:Number = Math.round(event.stageX);
    var myStageY:Number = Math.round(event.stageY);

    fl_MyInstance.x = myStageX;
    fl_MyInstance.y = myStageY;

        if(myStageX<150){
            fl_MyInstance.scaleX = fl_MyInstance.scaleY = 1-(myStageX/300);
        }else{
            fl_MyInstance.scaleX = fl_MyInstance.scaleY = 0.5;
            }
}

EDIT: Thanks for the answer. I will try to do this with an array, given that I want to make them removable later. The goal of the project is to create stars on the stage where you click and move the point from one star to another so that they glow when they hit them.

+3
2

, , :

...
var fl_MyInstance:LibrarySymbol = new LibrarySymbol();
fl_MyInstance.name = "symbol_" + i;
addChild(fl_MyInstance);
...

. , . .

...
var fl_MyInstance:LibrarySymbol = new LibrarySymbol();
_symbolList.push(fl_MyInstance)
addChild(fl_MyInstance);
...
+3

getChildren. - :

var children:ArrayCollection = this.getChildren();

foreach(var child:LibrarySymbol in children)
{
...do whatever
}

, getChild getChildAt - . , , .

: http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programming_08.html

+1

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


All Articles