A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Help with dynamic field...

  1. #1
    Member
    Join Date
    Jun 2002
    Posts
    71

    Help with dynamic field...

    Hi,

    Was wondering,
    I have a dynamic text field, with contents: "yellow, seven, house, bird"
    Is there an actionscript you know that will detect the commas and delete everything after it.

    For example,

    ", bird" would be deleted, "yellow, seven, house" would remain.

    And so on.


    Thanks,

    -rob

  2. #2
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    For this you need the slice and lastindexOf string functions. If you want to delete everything after the last comma
    code:

    str = "yellow, seven, house, bird";
    str = str.slice(0, str.lastIndexOf(","));


  3. #3
    Member
    Join Date
    Jun 2002
    Posts
    71
    Sorry,
    I see now it's the variable of the dynamic text field.

    It works great, thanks !

    -rob
    Last edited by rob88wells; 03-08-2004 at 07:39 AM.

  4. #4
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    str's a variable name in this case, the code would work just as well if you exchanged it for platypus. it's just good programming code to make it clear what purposes your variables are serving

    but make sure you don't name any variables with reserved words such as String or Number as these are built-in Flash objects and functions

  5. #5
    Member
    Join Date
    Jun 2002
    Posts
    71
    Ok.

    One more question,
    Because the first word (Yellow) has no comma in front of it, it is not all deleted at once, it's deleted character by character.
    Is there a way around this? Or do I have to put a comma infront of it?

    -rob

  6. #6
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    maybe just a quick if statement to see if there are any commas
    code:

    if(str.indexOf(",") <> -1) {
    str = str.slice(0, str.lastIndexOf(","));
    }else{
    str = "";
    }


  7. #7
    Member
    Join Date
    Jun 2002
    Posts
    71
    Thats exactly what i'm looking for!

    Thanks for all your help,

    -rob

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