PDA

View Full Version : outputting the mc name



j0se
August 25th, 2003, 12:24 PM
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?:)

kode
August 25th, 2003, 12:39 PM
myData(_parent._name+".txt");
?? :P

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

j0se
August 25th, 2003, 12:45 PM
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!

kode
August 25th, 2003, 12:48 PM
:P

You're welcome, j0se. ;)

j0se
August 25th, 2003, 01:05 PM
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?

kode
August 25th, 2003, 01:12 PM
If you always add the underscore before the suffix, you could use something like this:
// 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";

j0se
August 25th, 2003, 01:14 PM
that's much neater

ta!

kode
August 25th, 2003, 01:16 PM
You're welcome... again. :P