Skip to main content
Inspiring
Aug 17, 2006 10:59 PM UTC
Answered

targeting using a substring

I have an mc on the stage called car_mc which contains various mc's that are named:
spkr-a-0_mc
spkr-a-1_mc
spkr-a-2_mc
spkr-b-0_mc
spkr-b-1_mc
what i was trying to do is only target the substring "a" then have it perform an action, below is my script thats not working:
for (obj in car_mc) {
trace(obj);
//spkr-a-1_mc
if (typeof (car_mc[obj]) == "movieclip" and car_mc[obj]._name.substring(4, car_mc[obj]._name.indexOf("-")) == "a"){
car_mc[obj].play();
}
}
This topic is closed to new replies. Start a new post to keep the conversation going.
_Vee_Correct answer
Inspiring
Aug 18, 2006 2:54 PM UTC
Thank you both for your responses. I did a combo of both - removed the hyphens and fixed my starting and end point of the substring. I was confused about the start point, i thought you started at the character before not the actual character. Have a good weekend all and thanx.

4 replies

kglad
Community Expert
Community Expert
Aug 18, 2006 5:52 PM UTC
you're welcome.
Translate
kglad
Community Expert
Community Expert
Aug 18, 2006 12:59 AM UTC
first, don't use a dash in flash unless you mean to indicate subtraction because that's what flash will try and do when it encounters a dash: it will try and subtract a and 0_mc from spkr when it encounters spkr-a-0_mc.

fix that and then see if you have any problem.
Translate
_Vee_AuthorCorrect answer
Inspiring
Aug 18, 2006 2:54 PM UTC
Thank you both for your responses. I did a combo of both - removed the hyphens and fixed my starting and end point of the substring. I was confused about the start point, i thought you started at the character before not the actual character. Have a good weekend all and thanx.

Translate
Inspiring
Aug 18, 2006 12:57 AM UTC
Try this:

car_mc[obj]._name.substring(5, 6);

The letter index starts at 0, just like an array, so the 6th letter has index 5. If you just want the 'a' you don't need to use indexOf("-") for the second index. Otherwise, it should be indexOf("-",5) to avoid the first '-' before the a.

hth,
blemmo
Translate