Copy link to clipboard
Copied
I am very green with actionscript and coding in general so please forgive me if I am asking something that sounds super simple.
Is it possible to take "event.target.name" value which in my case would be something like "SW5005_mc" and change that value.
I use that value right now to tell another clip to gotoAndStop(event.target.name); which I have frames labeled the same as the event.target.name.
I would like to take the value of event.target.name for instance "SW5005_mc" and remove the "_mc" and put a dash in between the "SW" and the "5005"
to get "SW-5005" which then I would pass into a text field.
I really don't know where to begin or if this is possible.
Thanks for any help or suggestions,
Chris
1 Correct answer

You can use String.indexOf to find the _ and just get everything before it, then use substr and substring for the remainder:
var a:String = event.target.name;
var b:String = a.substring(0, a.indexOf("_")); //get the part before the _
var c:String = b.substr(0,2) + "-" + b.substr(2); //insert a - between first two chars and the remainder
trace(c);
SW-5005

Copy link to clipboard
Copied
yes you can do it with String manipulation, check out the various String Class methods, some examples here:
http://www.wuup.co.uk/as3-basics-string-manipulation-in-actionscript-3/
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html

Copy link to clipboard
Copied
You can use String.indexOf to find the _ and just get everything before it, then use substr and substring for the remainder:
var a:String = event.target.name;
var b:String = a.substring(0, a.indexOf("_")); //get the part before the _
var c:String = b.substr(0,2) + "-" + b.substr(2); //insert a - between first two chars and the remainder
trace(c);
SW-5005
Copy link to clipboard
Copied
Thank you both of you for the help I appreciate it.

