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

Chapter 10. Controlling Text > Analyzing Strings

Analyzing Strings

Use the methods of the String object to identify a character or characters in a string. The following tasks analyze input text fields to verify that the viewer has entered the required information.

To identify the position of a character:

Select the text tool in the Tools palette, and drag out a text field on the Stage.

In the Property Inspector, choose Input Text and Single Line from the pull-down menus, and enter an instance name for this input text field.

Create a button symbol, place an instance of it on the Stage, and give it a name in the Property Inspector.

Select the first frame of the main Timeline, and open the Actions panel.

Assign an onRelease handler to your button.

Choose Actions > Variables > set variable.

In the Variable field, enter a variable name.

In the Value field, enter the name of your input text field, followed by a dot and then the text property.

With the insertion point still in the Value field, choose Objects > Core > String > Methods > indexOf.

The indexOf() method appears after the text property. This method takes two parameters: searchString and fromIndex. The parameter searchString is the specific character you want to identify in the string. The parameter fromIndex, which is optional, is the starting position in the string (Figure 10.91).

Figure 10.91. Assign the indexOf() method to myString.text to search its contents for a specific character. The parameters for the indexOf() method have not yet been defined.

Between the parentheses of the indexOf() method, enter the character you want to find.

Make sure that you include quotation marks around the character.

Check the Expression checkbox next to the Value field (Figure 10.92).

Figure 10.92. This indexOf method searches myString.text for the % sign and puts the index in the variable characterPosition.

When your viewer enters information in the input text field and clicks the button you created, Flash searches the contents of the input text field for the specified character and assigns its position to your variable. Use this variable in the methods of the Selection, TextField, and String objects to modify the information further.



Not a subscriber?

Start A Free Trial

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