PDA

View Full Version : Changing Instance Name



JapanMan
March 21st, 2009, 10:27 PM
Is it possible to change an MC's instance name during the movie? I'm trying to make a game in which you can spawn 1 of several different units, but use the same MC for them all. Instead of creating them via an array (one reason for this would be b/c i may need a lot of arrays, which I don't know how to do), I want to name pre-existing MC's. Can this be done?

Gnoll
March 21st, 2009, 11:20 PM
Reference it as a different variable?

So you have 'mc' then


var newMc:MovieClip = mc

newMc.doSomething()

Hope that helps,
Gnoll

JapanMan
March 23rd, 2009, 10:29 AM
I see, thank you.

Gnoll
March 23rd, 2009, 04:32 PM
No problem,

Gnoll

JapanMan
March 24th, 2009, 11:26 AM
Will this method work to get information from a MovieClip? For example, MC1 has a variable
health = 50;I want to get the value of Health from the MC I click on in-game. If I use your code and say
var newMc:MovieClip = MC1;...can I get the Health value from "newMc"? Will
healthDisplay = newMC.health; work? If not, how can this be done?

DfKimera
March 24th, 2009, 01:30 PM
It will work, but the display won't always be up to date. That's because, AFAIK, unlike other objects, primitive objects like numbers and strings aren't passed as reference but as clones. So everytime you change newMC.health, you'd need to call healthDisplay = newMC.health again to update it.

JapanMan
March 24th, 2009, 07:26 PM
awesome. That is extremely helpful in project(s) I'm working on.

Gnoll
March 24th, 2009, 07:52 PM
Cool :)