开发者

Flash AS3 dynamically added children . Problem with naming them and calling each separated

I need to access each children after i dynamically added them to the stage , but i`m having problems figuring out how .

On click it adds the image to the stage , and I need to make them glow one at a time , with a for() , but I cant figure out how to name them each with its own name ( name + i ) to access them later on .

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: Thank you for your answers . I will try to do it with an array , considering that i want to make them removable later . The point of the project is to create stars across the stage where you click and have a dot move from one star to another making them glow when it hits them .


If you need to access them later by name you could do it by naming the symbols:

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

I would add them to an Array or Vector instead. That way makes it easy to access them later on. It is also good when disposing them.

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


You can access them in an array using getChildren. Something like this should work for you:

var children:ArrayCollection = this.getChildren();

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

If you want to access them individually you can use getChild or getChildAt or something similar. Using naming conventions with dynamic data is probably the hardest way to go through it.

Check here for more info: http://livedocs.adobe.com/flex/3/html/help.html?content=05_Display_Programming_08.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜