Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5943221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:21:51+00:00 2026-05-22T16:21:51+00:00

Assume I have the myCircle class all defined and all that. If my code

  • 0

Assume I have the myCircle class all defined and all that. If my code is as follows:

var circle1:myCircle = new myCircle()
var circle2:myCircle = new myCircle()
var circle3:myCircle = new myCircle()
var circle4:myCircle = new myCircle()

stage.addChild(circle1)
stage.addChild(circle2)
stage.addChild(circle3)
stage.addChild(circle4)

How would I write a function to return an array of [circle1, circle 2, circle3, circle4] automatically?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:21:51+00:00Added an answer on May 22, 2026 at 4:21 pm

    It’s simple, take a look at the following I made:

    package 
    {
        import flash.display.DisplayObject;
        import flash.display.DisplayObjectContainer;
        import flash.display.Sprite;
        import flash.events.Event;
    
        public class Main extends Sprite 
        {
            public function Main():void 
            {
                if (stage) init();
                else addEventListener(Event.ADDED_TO_STAGE, init);
    
            }// end function
    
            private function init(e:Event = null):void 
            {
                removeEventListener(Event.ADDED_TO_STAGE, init);
    
                for (var i:uint = 0; i < 5; i++)
                {
                    var circle:Circle = new Circle();
                    circle.name = "circle" + (i+1);
                    stage.addChild(circle);
    
                }// end for
    
                for (var j:uint = 0; j < 5; j++)
                {
                    var square:Square = new Square();
                    square.name = "square" + (j+1);
                    stage.addChild(square);
    
                }// end for
    
                traceNames(getCircles(stage)); // output: circle1
                                               //         circle2
                                               //         circle3
                                               //         circle4
                                               //         circle5
    
                traceNames(getSquares(stage)); // output: square1
                                               //         square2
                                               //         square3
                                               //         square4
                                               //         square5
    
    
                traceNames(getChildren(stage, Circle)); // output: circle1
                                                        //         circle2
                                                        //         circle3
                                                        //         circle4
                                                        //         circle5
    
            }// end function
    
            private function getCircles(container:DisplayObjectContainer):Array
            {
                var array:Array = new Array();
    
                for (var i:uint = 0; i < container.numChildren; i++)
                if (container.getChildAt(i) is Circle)
                array.push(container.getChildAt(i));
    
                return array;
    
            }// end function
    
            private function getSquares(container:DisplayObjectContainer):Array
            {
                var array:Array = new Array();
    
                for (var i:uint = 0; i < container.numChildren; i++)
                if (container.getChildAt(i) is Square)
                array.push(container.getChildAt(i));
    
                return array;
    
            }// end function
    
            private function getChildren(container:DisplayObjectContainer, type:Class):Array
            {
                var array:Array = new Array();
    
                for (var i:uint = 0; i < container.numChildren; i++)
                if (container.getChildAt(i) is type)
                array.push(container.getChildAt(i));
    
                return array;
    
            }// end function
    
            private function traceNames(array:Array):void
            {
                for each(var displayObject:DisplayObject in array)
                trace(displayObject.name);
    
            }// end function
    
        }// end class
    
    }// end package
    
    import flash.display.Sprite;
    
    internal class Circle extends Sprite
    {
        public function Circle() {}
    
    }// end class
    
    internal class Square extends Sprite
    {
        public function Square() {}
    
    }// end class
    

    The three key functions here are getCircles(), getSquares() and getChildren(). They all essentially do the same thing, theres a for loop in the function that loops through a specified display object container’s children. Upon each interation it checks the type for either Circle or Square types in the getCircles() and getSquares() functions respectively, and then it adds each display object to a local array which is returned by the function.

    The getChildren() function takes things a step further by allowing for the type to be specified beforehand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume we have legacy classes, that can't be modified: class Foo { public void
Assume i have a costum actionscript class. public class myClass { private var myVariable:ArrayCollection;
Assume we have a Menu class that has SubMenus (which is the same type
Assume I have a webpage where people submit java source code (a simple class).
Assume I have a class foo, and wish to use a std::map to store
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
Assume I have a form class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
Assume you have five products, and all of them use one or more of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.