In flash AS3 how do you create a movie clip with the name set at runtime?

in AS2:
createEmptyMovieClip(imgtext,index);

would create a movie clip with the string within imgtext as the name.

I need to create many movieclips on-the-fly that I can later interact with in code, it is easiest if I can set the name.
//AS2
imgtext = "img" + foldertext
createEmptyMovieClip(imgtext,index);

Open in new window

RoryRAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Try this:

<code>

-V
var foldertext:String = "1";
var imgtext:String = "img" + foldertext;
 
//adding an "empty MovieClip"
var anEmptyClip:MovieClip = new MovieClip();
anEmptyClip.name = imgtext;
stage.addChild(anEmptyClip);
 
//retrieving that MovieClip by it's name
var movieClipReference:Object = stage.getChildByName(imgtext);
 
//adding something else to that MovieClip
movieClipReference.addChild(new someMovieClip());

Open in new window

0
RoryRAuthor Commented:
this is my solution, using this[imagename] to create an object with any name. works to.

	var temp = e.target.url.split("/");
	var imagename = temp[temp.length-1];
	
	this[imagename] = new BitmapData(500,500);
	this[imagename]=imageloader.content;
	
	//testing
	this[imagename].x=Math.random() * 400;
	this[imagename].y=Math.random() * 400;
	this[imagename].width=100;
	this[imagename].height=100;
	
	pad.addChild(this[imagename]);

Open in new window

0
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
That solution you gave already existed in AS2.

Besides, the given solution works and answers the question.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

RoryRAuthor Commented:
it did exist in AS2, I wanted a way of doing the same action as createEmptyMovieClip(imgtext,index);

your's creates ones with the same symbol name but a different "name" property that you have to look up, mine creates it with that symbol name.

mine:
this[imagename] = new BitmapData(500,500);

beats:
var anEmptyClip:MovieClip = new MovieClip();
anEmptyClip.name = imgtext;
stage.addChild(anEmptyClip);
 
var movieClipReference:Object = stage.getChildByName(imgtext);
movieClipReference.addChild(new someMovieClip());
0
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
The point isn't about "beating" some other solution though.

I do agree that your solution works fine and is probably more efficient. However, my point is that the solution given also works and answers the question. I'm not trying to argue about it ;)

-V
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RoryRAuthor Commented:
good point, I get your reason for objecting :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.