<ActionScript 3 Bible 2nd>读书笔记(17)

  Using  Link  Events in TextField

         tf = new TextField(); 
         tf.selectable = false; 
         tf.defaultTextFormat = new TextFormat("_sans", 14); 
         tf.multiline = tf.wordWrap = true; 
         tf.width = 200; 
         tf.htmlText = "This text controls itself. You could turn it" + 
  ’ <a href="event:color,0xff0000"><u>red</u></a> or’ + 
  ’ <a href="event:color,0x00ff00"><u>green</u></a>. Or you could’ + 
  ’ <a href="event:move,20,0"><u>move it right</u></a> or’ + 
  ’ <a href="event:move,0,20"><u>move it down</u></a>.’; 
         tf.addEventListener(TextEvent.LINK, onLink); 
         addChild(tf); 
       }
 
 protected function onLink(event:TextEvent):void {
	var args:Array = event.text.split(","); 
	if (args.length < 1) return;
	switch (args.shift()) { 
		case "color":
 			colorText.apply(this, args); 
			break;
	 	case "move": 
			moveText.apply(this, args); 
			break; } }


获取当前系统的字体

      import flash.text.Font; 

           var fonts:Array = Font.enumerateFonts(true); 
           for each (var font:Font in fonts) { 
             if (font.fontName.match(/^comic\b/i) != null) { 
                found = true; 
                break; 
              } 
           } 
         } 
      } 
    } 
Pass it trueto include all device fonts; omit this parameter or use   false to include only embedded fonts. This method returns an array of  Fontinstances

fontStyle— The style of this font. Bold, italic, and bold+italic versions of the font must be embedded independently if you are to use any text in that font and style. All these embedded fonts will be instances of  Fontwith the same  fontNamebut different  fontStyles. This property is one of the constants  FontStyle.REGULAR, FontStyle.BOLD,  FontStyle.ITALIC, or FontStyle.BOLD_ITALIC. 

 fontType— Whether the font is a device font, an embedded font, or a embedded CFF font. These values are defined as constants in FontType. 


But the most important duty of  Fontis to register new fonts. If you load a SWF with an embedded font, you’ll need to do this step before you can use the font in TextFields. Once the embedded  font is registered with  Font, it can be referenced by font name by TextFormats and the like. Use the static method  Font.registerFont()to enable a font for use by passing its  Classreference. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值