您当前的位置: 首页 > 

Jave.Lin

暂无认证

  • 3浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

奇葩的as3 TextField

Jave.Lin 发布时间:2012-10-16 13:31:17 ,浏览量:3

这里列出来的是as3 TextField的奇葩之一:

当然,as3奇葩的东西,远远不止这些,这只是冰山一角;

如果设置tf的Format,则必须,以下两个语句一起使用;

否则,单单使用其一,格式还是会有很多丢失的;

				tf.defaultTextFormat=tfFormat;
				tf.setTextFormat(tfFormat);
大家可以,都我以下的源代码中的:两个no way 方法试试;先将must的隐掉;一个一个no way来设置;

package testTf
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	/**
	 *  [description]
	 * @author Jave.Lin(afeng)
	 **/
	[SWF(width="1200",height="720")]
	public class TestTf extends Sprite
	{
		public function TestTf()
		{
			super();
			
			stage.frameRate=60;
			stage.align=StageAlign.TOP_LEFT;
			stage.scaleMode=StageScaleMode.NO_SCALE;
			stage.color=0x888888;
			
			var aa:TextField = new TextField();
			
			setTf(aa,
				{
					visible:true,
					htmlText:"名称\ndsfasdfasfd\nasdfasdf",
					x:90,
					y:90,
					border:true,
					width:200,
					height:24*3,
					multiline:true,
					type:TextFieldType.INPUT
				},
				{
					size:19,
					color:0xff0000,
					align:TextFormatAlign.CENTER
				});
			
			addChild(aa);
			
			function setTf(tf:TextField,vars:Object,format:Object):void{
				var key:Object;
				for  (key in vars) 
				{
					tf[""+key]=vars[key];
				}
				var tfFormat:TextFormat=tf.defaultTextFormat;
				for  (key in format) 
				{
					tfFormat[""+key]=format[key];
				}
				
				//no way 1:
				//tf.defaultTextFormat=tfFormat;
				
				//no way 2:
				//tf.setTextFormat(tfFormat);
				
				//must :
				tf.defaultTextFormat=tfFormat;
				tf.setTextFormat(tfFormat);
			}
		}
	}
}

关注
打赏
1664331872
查看更多评论
立即登录/注册

微信扫码登录

0.0393s