Solved

flash: how to add elements dynamically ?

Posted on 2011-02-21
1
348 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
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 how to load their YouTube profile onto Flash Media Live Encoder.

756 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