Outputting the mc name

hello

i have a child mc with a loadVars event that gets some text from a file and loads it into a text box.

the parent mc is called about_us

what i want to do is tell loadVars to look for a file of the same name as the parent clip (instead of hard-coding the name - so i can reuse it in other clips in the same project)

this is what i have at the moment:

.
.
.
// load data
myData.load(“myFile.txt”);
.
.

whereas i want something like:
mydata.load(parent.name + “.txt”);

all the mc’s ahve an instance name, and i can do:
trace(this);
which gives me _root.parentclipname.loadVars_mc

but i want to output the parent clip name
trace(parent) and other combinations don’t work

can anybody help?:slight_smile:

[AS]myData(_parent._name+".txt");[/AS]
?? :stuck_out_tongue:

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary541.html

you saved the day again!!! :rambo:

thanks very much!

PS bloody syntax problems… i remember when it was all simple… :bad:

actually - what i now need to do is this:

//get parent name
parent_mc = _parent._name

// strip the “_mc” bit off the end
…
// then add the “.txt” extension

i’ll try and work this one out, but i will check here in an hour if i haven’t managed it (just to peek, in case the nice man with the god’s code book has told me how - again -

cheers!

:stuck_out_tongue:

You’re welcome, j0se. :wink:

i managed to do the last bit of what i wanted! i’m just wondering if this is the right way to do it:

// get the name of the parent mc
mc_name = _parent._name;

// strip the “_mc” bit off the end
// get the string length
stringLength = mc_name.length;

//strip last 3 characters
mc_name = mc_name.substring(0,(stringLength-3));

// add the “.txt” extension
mc_name = mc_name + “.txt”;

the obvious problem with this is that in order to reuse this code the names of the movie-clips must always have the “_mc” extension. i can’t think of why i might need to omit this in an mc’s name, but it still strikes me as a flaw

would you do it differently?

If you always add the underscore before the suffix, you could use something like this:
[AS]// get the name of the parent mc
mc_name = _parent._name;
// strip the “suffix" bit off the end
mc_name = mc_name.split("
”)[0];
// add the “.txt” extension
mc_name = mc_name+".txt";[/AS]

that’s much neater

ta!

You’re welcome… again. :stuck_out_tongue: