-
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
-
Senior Member
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(","));
-
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.
-
Senior Member
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
-
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
-
Senior Member
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 = "";
}
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|