• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 10. Controlling Text > Modifying Strings with the String Object

Modifying Strings with the String Object

There are two simple methods you can perform on a string to modify its characters: toUpperCase and toLowerCase. Both methods change the entire string to all uppercase letters or all lowercase letters. If you want to modify only certain letters to upper- or lowercase, you'll need to first create substrings of those specific characters as discussed in the previous section. Modify the substrings to upper- or lowercase, and then put the string back together with concat.

To change the case of characters in strings:

1.
Select the text tool, and drag a text box onto the Stage. In the Text Options panel, select Input Text and Single Line in the pull-down menus. Enter a variable name for this input text box.

2.
Select the text tool, and drag out another text box onto the Stage. In the Text Options panel, select Dynamic Text and Single Line in the pull-down menus. Enter a variable name for this dynamic text box.

3.
Create a button symbol, and place an instance of it on the Stage. Select it, and open the Actions panel.

4.
Choose Actions > set variable. In the Variable field, enter the name of your dynamic-text variable. In the Value field enter the name of your input-text variable. Then choose Objects > String > toUpperCase. Check the Expression box.

The toUpperCase method appears in the Value field after your input-text variable. No parameters are required for this method because it will convert the entire string to uppercase characters (Figure 10.78).

Figure 10.78. The toUpperCase method converts the characters in the variable called myInput to uppercase.


5.
Test your movie.

When your viewer enters text into the input text box and clicks the button you created, Flash modifies the entire string to uppercase and displays the results in the dynamic text box (Figure 10.79).

Figure 10.79. The results of the toUpperCase method show in the dynamic text box called display.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint