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

Can you use a variable in place of movieclip linkage for addchild?

New Here ,
Jun 17, 2013 Jun 17, 2013

var top:MovieClip = MovieClip(root);

top.menu3.addChild(member[i-1].scenarioplayed);

I want to add components to a movieclip depending on value of i.

The movieclips are named menu3, menu4, etc.

Is there a way to make all are part of "top.menu3" a variable?

I tried this but got a compile error:

Symbol 'scene3', Layer 'Actions', Frame 1, Line 1611061: Call to a possibly undefined method addChild through a reference with static type String.

var menuName:String;

menuName = "top.menu5";

menuName.addChild(member[i-1].scenarioplayed);

TOPICS
ActionScript
504
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

correct answers 1 Correct answer

LEGEND , Jun 17, 2013 Jun 17, 2013

For the code you just showed, menuName is a String.  String do not have an addChild method.

It is not clear what you are working with to get what you want, but if you want to use String values to target objects you can use the bracket notation...

var menuObject:MovieClip = top["menu5"];

menuObject.addChild(member[i-1].scenarioplayed);

Translate
LEGEND ,
Jun 17, 2013 Jun 17, 2013

For the code you just showed, menuName is a String.  String do not have an addChild method.

It is not clear what you are working with to get what you want, but if you want to use String values to target objects you can use the bracket notation...

var menuObject:MovieClip = top["menu5"];

menuObject.addChild(member[i-1].scenarioplayed);

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
New Here ,
Jun 17, 2013 Jun 17, 2013

Can menu5 then be a variable?

var menu:string = "menu5";

var menuObject:MovieClip = top[menu];        // Can variable be placed here

menuObject.addChild(member[i-1].scenarioplayed);

I went to use a switch statement to send component to right movieclip.

switch (true)

            {

                      case i > 34:

                        {

                                        q = 34;

                                        menu = "menu5";

                                        break;

                              }

                      case i > 17:

                        {

                                        q = 17;

                                        menu = "menu4";

                                        break;

                              }

                     case i < 18:

                       {

                                 q = 0;

                                 menu = "menu3";

                                 break;

                       }

then add following for placement

var menuObject:MovieClip = top[menu];        // Can variable be placed here

menuObject.addChild(member[i-1].scenarioplayed);

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
New Here ,
Jun 17, 2013 Jun 17, 2013
LATEST

BTW, I have the project I am working on up at http://www.ragtopvideo.com/testpage.html

The team link is the only one working now.  It can do up to 17 team members, this part

is meant to spill over larger numbers onto other pages/movieclips.

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