Help with strings

Hey all,
here’s the problem. I’m making a small application to send sms messages. I have a box to enter in the message, and a counter which counts down towards zero as you enter each character. For my counter I have the code:
[AS] onClipEvent(enterFrame) {
counter=160-_parent._parent.login.length-_parent.message.length;
}
[/AS]
(login is the name of sender which also needs to be removed from the length)
what I want to do is add an if statement so that if the counter falls below zero, the last character of the message is deleted.
yours hopelessly, [Lego]

What you could do is set the maxChars for the input textbox to be the leftover amount after the login…

For example (don’t know if it will work as is, but it’s a point in the right direction)…

[AS]
var totalChars = 160;
var login = _parent._parent.login.length;
var totalInputLeft = totalChars-login;
_parent.message.maxChars = totalInputLeft;
[/AS]

totalChars is the variable to whole the maximum amount of characters used overall

login is a variable to hold the length value of the login textbox

totalInputLeft is a variable that subtracts the login length fromt he totalChars amount leaving that as the maximum amount of characters left to use in the message textbox

_parent.message.maxChars = totalInputLeft targets the message textbox and sets its maxChars property to the amount that is able to still be type (the amount set by the totalInputLeft variable)

thanks lost, it was the maxChars thing that I needed didn’t know about that since I ain’t done much with strings before, cheers.

Ok, I realized my script is inaccurate in that it assumes the login is already filled in when the frame is hit so it sets it by that… here is another thing using TextField.onChanged() (when a textfield changes the code is run)

I did a test and it worked well… my code assumes the code and the textboxes are in the same timeline, so adjust as you need…

[AS]var totalChars = 30;
login.maxChars = totalChars-1;
login.onChanged = function() {
message.maxChars = totalChars-this.length;
};[/AS]

totalChars is the variable that holds the total amount of characters altogether (I did 30 for testing purposes)

login is an input textbox and login.maxChars = totalChars-1 sets that input textboxes maximum character limit to the amount of the totalChars variable minus 1. Why minus 1? Simple… if you don’t minus one… then if the login was (in this case) 30 characters long, then the result of “totalChars-this.length” later in the script will equal “null” and if that happens, then no limit will be set for the message input box.

login.onChanged = function() {
message.maxChars = totalChars-this.length;
};

When the login input textbox is changed, you willr eset the message input textboxes maxChars property to the new value of totalChars-this.length (this.length being login.length)

So in essense we have…

-Set a maximum total amount of characters
-set the login maximum amount of characters
-use an onChanged() handler to check how many characters were used up in the login textbox
-finally set the message textbox to the leftover maximum amount of characters

thanks again for your time&effort lost. I managed a solution using the maxChars thing but onChanged() might come in handy if I decide to jig things about a bit, and definitely worth noting for future use.
now I’m onto getting PHP involved, I’m sure I’ll be back posting if I run into trouble with that :wink: ciao ciao, tiger.