Text Editor (2): TextField Solution

Source: Internet
Author: User

Source code download

When I first received this requirement, I thought it should not be complicated. I have also seen many text editors. There are too many and too many websites.
But then the problem arises:

Problems:
● How do I enter Chinese Characters in as3?
◎ If it is created in Flash CS, drag a Text box to the stage. Let me tell you. You are amazing. You will not face this problem.
Because the Text dragged from the tool in Flash supports Chinese input.
◎ This problem will not be faced by the pure AS3 Project
◎ This problem occurs in the dynamic text box of the Flex project.As3 dynamic text box input in Chinese is Adobe's Bug

 

"The problem always comes when you are not ready." _ quotations from diaosi programmers

A hard-pressed programmer always chooses the most difficult and dangerous path.
Buddha said: Heaven has a way you do not go, hell has no door you come.
Diaosi programmer: I do not go to hell. Who is going to hell?

I just need to add this tool in Flex: But there is also a solution: I checked n more information to package the Chinese font.
These are all online. However, I asked an old bird who has been developing Flash for many years. He quietly told me the following content:

"Add flash. system. IME. enabled = true to the FocusEvent. FOCUS_IN event listener of TextField ;"

Flash. system. IME. enabled = true; // flash lowercase
/* Using the IME class, you can directly operate the Input Method Editor (IME) of the operating system in the Flash runtime application running on the client computer. You can determine whether IME is installed, whether IME is enabled, and which IME is enabled. You can disable or enable IME in the application and execute other restricted functions, depending on the operating system. */

● Obtain the local Font name: Font. enumerateFonts (true );
Return: Array System Font set [Font, Font...]
The array element is a Font object, and the name is obtained through the fontName of the Font object.

● Font setting: TextFomat. font = "" is not allowed"
Conversion between Chinese and English Fonts

Var tfm: TextFormat = new TextFormat (FontNames. getFontEnglishiName (fontList. selectedItem. label ));
Tfm. font = fontEnglshiName;
If (_ txtInput. selectionBeginIndex <_ txtInput. selectionEndIndex)
{
_ TxtInput. setTextFormat (tfm, _ txtInput. selectionBeginIndex, _ txtInput. selectionEndIndex );
}

 

● Set the style of the selected text: flash. text. TextField. setTextFormat (format: TextFormat, beginIndex: int =-1, endIndex: int =-1): void

Var txtStarIndex: int = txtInput. selectionBeginIndex; // The selected Start index var txtEndIndex: int = txtInput. selectionEndIndex // The selected end index var tfm: TextFormat = new TextFormat ();
Tfm. color = fontColorPicker. selectedColor; _ txtInput. setTextFormat (tfm, txtStarIndex, txtEndIndex );

● Bold: unlike other styles, you can apply the settings to the selected content. Bold and different
Rough will make: rough and cancel rough judgment
Click "bold" to judge as follows:

Private function setBoldFomate (): void
{
// Obtain the style of the selected text of txtField
Var tf: TextFormat = _ txtInput. getTextFormat (_ txtInput. selectionBeginIndex, _ txtInput. selectionEndIndex );
Var tfm: TextFormat = new TextFormat ();
If (tf. bold = false | tf. bold = null)
{
// Bold
Tfm. bold = true;
_ TxtInput. setTextFormat (tfm, _ txtInput. selectionBeginIndex, _ txtInput. selectionEndIndex );
} Else {
// Cancel bold
Tfm. bold = false;
_ TxtInput. setTextFormat (tfm, _ txtInput. selectionBeginIndex, _ txtInput. selectionEndIndex );
}}

● TextFiled Htmltext can be read and written
You can set htmlText = "<Font size =" "color =" "> <B> </Font>"
Set content for TextField. At the same time, we changed the TextField by setting TextField. setTextFomat. At this time, we read the htmlText of TextField.
The system will return the htmlText description of the current TextField to us.

● A large number of regular expression applications

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.