AS3-元数据Embed嵌入说明

2012-07-05 10:15:15

<pre class="ql-syntax" spellcheck="false"><span class="hljs-comment">/* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;没有设置,Flash会在源属性中根据导入资源文件的扩展名载入合适的类型 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Flash不能通过XML文件的扩展名检测正确的MIME类型,嵌入XML数据时都要设置mimeType参数 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application/x-font&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application/x-font-truetype&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application/x-shockwave-flash&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;audio/mpeg&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image/gif&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image/jpeg&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image/png&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image/svg&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image/svg-xml &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;application/octet-streamQ&nbsp;&nbsp;&nbsp;任意的二进制数据&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;*/</span> &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<span class="hljs-class"><span class="hljs-keyword">class</span>&nbsp;<span class="hljs-title">Main</span>&nbsp;<span class="hljs-keyword">extends</span>&nbsp;<span class="hljs-title">Sprite</span>&nbsp;</span>{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment">//元数据:[Embed]元数据标签仅仅支持类和成员变量</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Embed(source=<span class="hljs-string">"asset/Main.swf"</span>,symbol=<span class="hljs-string">"mc"</span>)]<span class="hljs-comment">//绑定库元件名</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<span class="hljs-keyword">var</span>&nbsp;mc:Class; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Embed(source&nbsp;=&nbsp;<span class="hljs-string">"img/01.jpg"</span>)] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;&nbsp;<span class="hljs-keyword">var</span>&nbsp;img:Class; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Embed(source=<span class="hljs-string">"asset/Item.xml"</span>,mimeType&nbsp;=&nbsp;<span class="hljs-string">"application/octet-stream"</span>)] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<span class="hljs-keyword">var</span>&nbsp;_xml:Class; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-comment">//描述了嵌入元数据的MIME类型</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Embed(source&nbsp;=&nbsp;<span class="hljs-string">"asset/font.ttf"</span>,&nbsp;fontName&nbsp;=&nbsp;<span class="hljs-string">"myfont"</span>,advancedAntiAliasing=<span class="hljs-string">"true"</span>,&nbsp;mimeType=<span class="hljs-string">"application/x-font"</span>)] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;<span class="hljs-keyword">var</span>&nbsp;theClass:Class; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;<span class="hljs-function"><span class="hljs-keyword">function</span>&nbsp;<span class="hljs-title">Main</span>()&nbsp;</span>{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(<span class="hljs-keyword">new</span>&nbsp;_xml()) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword">var</span>&nbsp;format:TextFormat&nbsp;=&nbsp;<span class="hljs-keyword">new</span>&nbsp;TextFormat(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.size&nbsp;=&nbsp;<span class="hljs-number">14</span>; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.font&nbsp;=&nbsp;<span class="hljs-string">"myfont"</span>; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword">var</span>&nbsp;txt:TextField&nbsp;=&nbsp;<span class="hljs-keyword">new</span>&nbsp;TextField(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txt.text&nbsp;=&nbsp;<span class="hljs-string">"方正粗活意简体"</span>; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txt.embedFonts&nbsp;=&nbsp;<span class="hljs-literal">true</span>; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;txt.setTextFormat(format); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword">this</span>.addChild(txt); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;} </pre><p>&nbsp;</p><p>&nbsp;</p><p><strong>在纯AS3项目中嵌入字体</strong></p><pre class="ql-syntax" spellcheck="false">[Embed(source=<span class="hljs-string">"04b_08.ttf"</span>,fontName=<span class="hljs-string">"04b_08"</span>,embedAsCFF=<span class="hljs-string">"false"</span>,unicodeRange=<span class="hljs-string">"U+0020,U+0041-005A"</span>)] publicvar myFont:Class; </pre><p>使用传统方式(就是上面图2中提到的“传统”)嵌入字体名为04b_08的TTF字体中的英文、数字和标点符号,包含大小写。</p><p>来看看这四个常用参数的作用吧:</p><p><br></p><ul><li>source 指定要嵌入的字体文件路径。还可以用 systemFont指定一个系统中安装的字体。这样的话就可以不需要 source参数了。</li><li>fontName 这个实际上就是 fontFamily 的别名。</li><li>embedAsCFF 如果不提供这个参数,默认就是true;所以,如果系统你嵌入的字体用于TextField,一定要将其设置为false。</li><li>unicodeRange 要嵌入的文本的范围。默认范围大小写,数字,符号</li></ul><p><br></p><p>嵌入字体范围:</p><ul><li>大写字符 U+0020,U+0041-U+005A</li><li>小写字符 U+0020,U+0061-U+007A</li><li>数字 U+0030-U+0039,U+002E</li><li>标点符号 U+0020-U+002F,U+003A-U+0040,U+005B-U+0060,U+007B-U+007E</li><li>基本拉丁字符 U+0020-U+002F, U+0030-U+0039, U+003A-U+0040, U+0041-U+005A, U+005B-U+0060, U+0061-U+007A, U+007B-U+007E</li><li>中文字符&nbsp;&nbsp;&lt;lang&gt;Chinese (All)&lt;/lang&gt;</li><li>&nbsp;&nbsp;U+3000-303F,U+3105-312C,U+31A0-31BF,U+4E00-9FAF,U+FF01-FF60,U+F900-FAFF,U+201C-201D,U+2018-2019,U+2014,U+2026,U+FFE5,U+00B7</li></ul><p>中文范围等等,详细的可以找到你本机的 FlexSDK/frameworks/flash-unicode-table.xml 看看就明白了(中文chinese)</p>