A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How to grab number at end of moviclip name as a var?

  1. #1
    Junior Member
    Join Date
    Jul 2009
    Posts
    15

    How to grab number at end of moviclip name as a var?

    Hi

    I have some buttons named bt1, bt2, bt3 etc

    They have a common function for when each is clicked called buttonclicked.

    Within the function buttonclicked, I'd like to grab the number off the end of each button name so that I can compare the number to a global variable I have called global.data.clicker

    so...

    if (number at end of event.target.name == global.data.clicker) {take action...

    Is it possible, and if so, what code do I need to put in the first part of the if statement to make it work?

    Thanks for your time and help.

    Shaun

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Use the substr method of the string class. So it would look something like this,
    Actionscript Code:
    event.currentTarget.name.substr(2); // 0 based index b = 0, t = 1, # = 2.

    Try that.
    Wile E. Coyote - "Clear as mud?"

  3. #3
    Junior Member
    Join Date
    Jul 2009
    Posts
    15
    Much appreciated Robb - works perfectly.

    Thank you

    Shaun

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center