Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

flash: how to add elements dynamically ?

Posted on 2011-02-21
1
Medium Priority
?
358 Views
Last Modified: 2012-05-11
Hello, I have in my Fla (cs5) these symbols:
Backgorund1
Background2
Background3

All these extends MovieClips

My goal is to add them dynamically to stage accordign to level variable:
ex:

   var level:int = 1;
   
    var bg:MovieClip =new getClassByName("Background"+level);
   
    stage.addChild(bg);



Any idea on how to do that ?

Regards
0
Comment
Question by:yarekGmail
1 Comment
 
LVL 1

Accepted Solution

by:
nightmare3d earned 2000 total points
ID: 34951676
hi,

you can do this:




var dynamicClass:String = "background" + String(level);
var classRef:Class = getDefinitionByName(dynamicClass) as Class;
var mc:MovieClip = new classRef();
addChild(mc)

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question