[Original] Implementation of Word's bulk replacement, AS dynamic text features --- Stringutil
Another original class after the last SimpleDateFormat (formatted date class), everyone review, continue to work hard, huh, huh.
This is a few days, now 1.0, Stringutil is a string tool class, saying that it is a text tool class, and now you can implement these features:
1. Batch replacement function, with the Replace (STR, STR2) method, can replace STR in the formulated text to STR2,
2. The text in the text will be developed to convert to MC with getMovileclip () so that you can use control MC to control these characters, simply make text effects. Return MovieClilp array
3. Will make each character in the text, as an array element, return an array
code show as below
/ **
* Title: String Tool Class
* DESCRIPTION: Tools
* Company:
* CopyRight
* @Author wei386
* @version 1.0
* /
Class Stringutil Extends string {
Private var stringObject: string;
Private var mcArray: array;
/ **
* Set string
* @Param Str will operate the string
* @Return Void
* /
Function setText (STR): Void
{
THIS.STRINGOBJECT = STR;
}
/ **
* Get the string of the current Stringutil object
* @Param Str will operate the string
* @Return Void
* /
Function getText (): String
{
Return this.StringObject;
}
/ **
* Replace the characters in the string
* @Param Findstr Find strings
* @Param Replstr will be replaced string
* @Return String
* /
Function Replace (FINDSTR: STRING, REPLSTR): String {
Var Strindex: Number = 0;
StrINDex = StringObject.indexof (Findstr);
For (;;) {
IF (StrIndex == -1 | Laststrindex == - 1) {
Return this.StringObject;
}
/ / Get the start character
Var StartStr = this.stringObject.substring (0, Strindex)
/ / Get the last character
Var laststr = this.stringObject.substring (Strindex FindStr.Length, this.stringObject.length);
/ / Find in the last character to have a character to replace
Var laststrindex = laststr.indexof (Findstr)
this.StringObject = StartStr Replstr Laststr
// Set the start character interception position, so that only the characters that have to be replaced each time
Strindex = STRINDEX Laststrindex Replstr.LENGTH
}
}
/ **
* Returns the character array of strings, returns every character of the string as the element of the data.
* @Param
* @Return Array
* /
Function getchar (): array {
Var stratay = new array (StringObject.length);
For (var i = 0; i } Return stratay; } / ** * Get objects with a string for MovieClilp, an array of moviClip * @Param Strcolor text color * @Param strsize text size * @Return Array * / Function GetMovieClip (Strsize: Number): Array { // Declare an array, store the MC object THIS.MCARRAY = New Array (StringObject.length); For (VAR i = 0; i // Declare the name of the MC Var mcarray_name: String = "Stringutil.mc _" i // Create an empty MC on a 100,000 layer, named "Stringutil.mc_" i _LEVEL0.CREATEEMPTYMOVIECLIP (McArray_name, 10000000 i) // Put this MC I array object McARRAY [i] = _ level0 [mcarray_name] / / Define the name of TextField Var textfieldname = mcArray [i] ._ name; // Create a TextField on the MC McARRAY [i] .createtextfield (TextfieldName, 10000000 i, 0, 0, 100, 100); // Set the character of TextField McARRAY [i] [textfieldname] .Text = StringObject.Charat (i); // Setting the text is not available McArray [i] [textfieldname] .selectable = false Var textFormat: textformat = new textFormat (); Textformat.color = strcolor; Textformat.size = strsize; McARRAY [i] [textfieldname] .SetTextFormat (TextFormat); } Return mcArray; } } Instructions: Create a new FLA file, write Var strutil = new stringutil (); Strutil.Settext ("xxxx my home"); // Set the text you want to operate Replace the string method: Strutil.Replace ("I", "We"); You can change the strut "XXXX My Home" in the strut "XXXX My Home" to "We" Change the character to MOVIECLIP: Var mcarray = strutil.getmovieClip (0x0099cc, 50) You can convert each character in "XXXX My Home" into MC, 0x0099cc is the color of the word, 50 is the size, the return McARRAY is an array Convert to MC size can be used with mcarray [i] ._ width, mcarray [i] ._ height is controlled, just like MC, then you can do your own text effect. This class can be used to do AS lyrics, as long as each setText (), different strings, each lyrics, you can.