Since the flash support for Chinese is not very good, many people have found that many Chinese characters in the flex can not be set in bold, is one of the performance, after a night of tossing, finally broke through the problem, in fact, the answer is in the official Adobe Tutorial, can only blame their English level is too poor, nonsense not table, Straight into the chase, for the sake of description, take Google's source blackbody as an example:
The first step: compiling fonts into SWF files
Copy the fonts you need (normal and bold two font files separately) into your own program, and here I copy the NOTOSANSHANS-REGULAR.OTF and NOTOSANSHANS-BOLD.OTF of the Siyuan blackbody to the src root directory ( These can be deleted after compilation, and then build syht.css in the root directory as follows:
/* CSS file */@namespace S "Library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/mx"; @ Font-face{src:url (' Notosanshans-regular.otf '); font-family:syht;font-weight:normal;embed-as-cff:true;} @font-face{src:url (' Notosanshans-bold.otf '); font-family:syht;font-weight:bold;embed-as-cff:true;}
Then right: Compile CSS to SWF, compiled will be generated in the target folder syht.swf file, this is a font file containing the source blackbody, then you can delete the font files and syht.css, to avoid the project in the re-compilation time consuming.
Step two: Load the font file
Load the font file during the initialization phase of the main program, where I put the syht.swf in the program root directory.
protected function Application1_initializehandler (event:flexevent): void{ FlexGlobals.topLevelApplication.styleManager.loadStyleDeclarations2 ("syht.swf", True);}
The main program in the above code loads the syht.swf font file immediately after loading is complete
Step three: Add a reference to Embeddedfontregistry
Import Mx.core.EmbeddedFontRegistry in the main program;
<fx:Script> <![ cdata[ import mx.core.FlexGlobals; Import mx.events.FlexEvent; Import Mx.core.EmbeddedFontRegistry; Embeddedfontregistry; protected function Application1_initializehandler (event:flexevent): void { FlexGlobals.topLevelApplication.styleManager.loadStyleDeclarations2 ("syht.swf", True); } ]] ></fx:Script>
Fourth Step: Add compilation Options-theme+=frameworks\projects\spark\mxftetext.css
If you are not prompted to find the file, please go directly to the SDK package in the corresponding directory to find and copy to the program, such as copy to the root directory, then-theme+=mxftetext can
Then you can set the FONTFAMILY=SYHT to apply the font, usually set the default font in the global style, I will not write code.
In addition, if it is Flex3, then ignore the fourth step, and the first step of the CSS EMBED-AS-CFF please set to False
The ultimate solution for Flex Chinese fonts