• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to put in a Array the names of the children in object container?

Valorous Hero ,
Mar 20, 2010 Mar 20, 2010

Copy link to clipboard

Copied

I can't come up with a function that will collect the names of the children in a object container and put them in a array.

Any ideas?

TOPICS
ActionScript

Views

531

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 20, 2010 Mar 20, 2010

For example:

function collectChildren(container:DisplayObjectContainer):Array {
     var len:int = container.numChildren;
     var array:Array = [];
     for (var i:int = 0; i < len; i++)
     {
          array.push(container.getChildAt(i).name);
     }
     return array;
}

Votes

Translate

Translate
LEGEND ,
Mar 20, 2010 Mar 20, 2010

Copy link to clipboard

Copied

For example:

function collectChildren(container:DisplayObjectContainer):Array {
     var len:int = container.numChildren;
     var array:Array = [];
     for (var i:int = 0; i < len; i++)
     {
          array.push(container.getChildAt(i).name);
     }
     return array;
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 20, 2010 Mar 20, 2010

Copy link to clipboard

Copied

Thanks a lot Andrei1,

I was trying with the instance of the Array class and failed, I didn't realize it could be done with a function of type Array.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 21, 2010 Mar 21, 2010

Copy link to clipboard

Copied

You are welcome.

Functions can return any datatype.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 21, 2010 Mar 21, 2010

Copy link to clipboard

Copied

LATEST

That :Array you see is not defining the class of the function.  It identifies the class of the object returned by the function.  That's why in most functions you probably see :void in that spot... identifying that the function doesn't return anything

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines