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

How do i addChild from within an .AS class?

Guest
Mar 20, 2013 Mar 20, 2013

i have a class that contains multiple Shapes... i want to apply addChild to all of these at once from within the class... something like:


public class MultiShape
{

      private var shapes:Vector.<Shape> = new Vector.<Shape>(3) ;

      public function MultiShape()

      {

            var i:int ;

            for ( i = 0 ; i < 3 ; i++)

            {

                      shapes = new Shape() ;
                      // setup shapes appaearance

                     addChild( shapes) ;   // *** doesn't work ***

            }

     }

}

i create instances of the class in the timeline code... there i can use 'addChild' by itself to add disply objects to the stage, as if the stage is 'this'... i would like to use/refer the stage in the class to be able to use 'addChild' to add the graphic Shape elements to the stage... but this i don't think is allowed...

a possible work around i considered was to create a Shape in the timeline, add it to the stage, wait for it to be added, and pass this Shape to the class so it could use that Shape's 'stage' property... but that seems a bit convoluted...

i should point out my class does not extend anything... it is meant to be a collection of graphic elements treated as one object...

TOPICS
ActionScript
416
Translate
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
Guest
Mar 20, 2013 Mar 20, 2013
LATEST

ok... i figured it out... a 'Sprite' is really also a DisplayObjectContainer... so if i make my class an extension of Sprite i can 'addChild' to the Sprite and then add them all to the stage at once by adding Sprite to the stage...

Translate
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