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
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 -
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
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]