Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with event.target.name

Explorer ,
Oct 29, 2009 Oct 29, 2009

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

TOPICS
ActionScript
699
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Oct 29, 2009 Oct 29, 2009

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

Translate
Guest
Oct 29, 2009 Oct 29, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 29, 2009 Oct 29, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 29, 2009 Oct 29, 2009
LATEST

Thank you both of you for the help I appreciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines