Core Objects
String object
You have been working with strings of text from the start of the Flash basic course. However you may be surprised that String is also an object, which have many useful methods to manipulate with text.
It is possible to find out what are the characters on each place of the text, and on what place the certain character is located. You may transform the text to uppercase or lowercase, split it and extract parts of it.
- In new file create an Input text box and assign variable yourname to it
- Make four dynamic texts and assign each a variable firstchar, length, uppercase, lowercase
- Add static label texts like in our example
- Add the button with the following code
on (release) { s = new String(); s = yourname; firstChar = s.charAt(0); lowercase = s.toLowerCase(); uppercase = s.toUpperCase(); length = s.length; }In the code we created a new string object "s" and assigned to it the value of the input text box. Then we used methods and property length to update information about string.See how we found the first letter of the string – it's under index 0 of charAt() method