AS3文本字段自动滚动至底部 [英] AS3 TextField autoscroll to the bottom

查看:435
本文介绍了AS3文本字段自动滚动至底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自动滚动的文本字段底部的动作,同时添加文本编程方式有:

How to autoscroll to the bottom of the TextField in ActionScript while adding text there programmatically:

var _output:TextField = new TextField();
for (var i:int = 0; i < 100; ++i) {
    _output.appendText("Hello World!");
}

亦认为,文本字段的垂直滚动应启用,一旦一个新的文本然后再加入自动滚动到底部应再次执行。

Also consider that the vertical scrolling of the TextField should be enabled, and once a new text was added then autoscroll to the bottom should be executed again.

推荐答案

您应该听 Event.CHANGE 上所讨论的文本字段事件。 <一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#event%3achange"相对=nofollow>描述相事件到文本框如果你捕捉到这个事件,您与则scrollV 性能发挥。再说了,像这样的:

You should listen for Event.CHANGE event on the TextField in question. Event description relative to textField And if you capture this event, you play with scrollV property. Say, like this:

_output.addEventListener(Event.CHANGE,scrollAllDown);
function scrollAllDown(e:Event):void {
    var tf:TextField=(e.target as TextField);
    if (!tf) return; 
    tf.scrollV=tf.maxScrollV;
}

更新:捕获 Event.CHANGE 不工作,我离开这个万一有人跌倒这种方法太发现这是行不通的。因此,唯一的办法是继承文本字段和手动覆盖 appendText()方法,包括滚动,像这样:

Update: Catching Event.CHANGE does not work, I leave this in case someone stumbles on this method and too finds out it doesn't work. So, the only way is to subclass the TextField and manually override appendText() method to include scrolling, like this:

public class OutputTF extends TextField 
{ 
    // constructor omitted
    override public function appendText(text:String):void 
    { super.appendText(text); this.scrollV=this.maxScrollV; } 
}

这篇关于AS3文本字段自动滚动至底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆