flash输入文本框:Flash动态文本框内动态文本内容自适应

  本文举例源代码或素材下载

  这样道题有关Flash:Flash场景中有个文本框长和宽是已知但是值不固定(可能是10×20也可能是462×139还有可能其他)然后我们有串长度已知但是同样不固定(可能1个字也可能562个字还可能其他)目前我们要实现调整字大小使这些字要填满这个文本框不能有滚动(字要完全显示出来)也不能空很大空出来最好刚刚填满

  这个问题困扰了我3、4天了还是没有办法解决其中些问题写下我实现办法

  先我设想文本框和场景样大拖动Flash影片时候文本框长宽自然改变但是值也是可以通过Stage获取然后文本内文字设置个变量现在问题就变成无论如何拖动这个Flash里面自都是满满填满了真个文本框没有隐藏也没有太多空白如下图

Flash动态文本框内动态文本内容自适应

  我代码

stop;
Stage.scaleMode = “noScale”;
Stage.align = “TL”;
Stage.showMenu = false;
var i_txt:String = “其实电脑方面懂太少其实电脑方面懂太少其实电脑方面懂太少”;
var t_w:Number = Stage.width-10;//减去边框霓虹灯宽度
var t_h:Number = Stage.height-10;//减去边框霓虹灯高度
  
var xn:Number = Math.ceil(Math.sqrt(i_txt.length * ((Stage.width-14) * 76) / (67 * (Stage.height-14))));//是对每行字体个数估算下面是对字行数估算问题就在这里
var yn:Number = Math.ceil(i_txt.length/xn);
Property(”_root.nhd_b”, _y, Stage.height-3);//霓虹灯宽3像素这里设置霓虹灯底部边框
Property(”_root.nhd_r”, _x, Stage.width-3);//霓虹灯右边边框
this.createTextField(”my_txt”, this.getNextHighestDepth, 5, 5, t_w, t_h);//画出文本框
my_txt.type = “”;
my_txt.multiline = true;
my_txt.border = true;
my_txt.wordWrap = true;
my_txt.selectable = true;
my_txt.hscroll = 0;
my_txt.text = i_txt;
var my_fmt:TextFormat = TextFormat;
my_fmt.size = Math.floor((t_w-4)/(xn));//估算字大小
my_fmt.color = 0xFF0000;
my_fmt.align = “left”;
my_fmt.leftMargin = 0;
my_fmt.rightMargin = 0;
my_fmt.indent = 0;
my_fmt.leading = 0;
my_fmt.letterSpacing = 0;
my_fmt.kerning = true;
my_txt.TextFormat(my_fmt);
var sizeLis = Object;
sizeLis.onResize = function {
Property(”_root.nhd_b”, _y, Stage.height-3);
Property(”_root.nhd_r”, _x, Stage.width-3);
var xn:Number = Math.ceil(Math.sqrt(i_txt.length * ((Stage.width-14) * 76) / (67 * (Stage.height-14))));
var yn:Number = Math.ceil(i_txt.length/xn);
my_txt._width = Stage.width-10;
my_txt._height = Stage.height-10;
my_fmt.size = Math.floor((Stage.width-10-4)/(xn));
};
Stage.addListener(sizeLis);


Tags:  flash动态文本 动态文本框 flash文本框 flash输入文本框

延伸阅读

最新评论

  1. TextField.autoSize=true 就可以自动适应了

发表评论