AS3文本框更改事件不触发 [英] AS3 Textbox Change Event Not Firing

查看:292
本文介绍了AS3文本框更改事件不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建了一个竞猜游戏,卡通泡沫的问题。泡沫是再大的问题的长度。我想在动态文本框更改事件调用改变的问题气泡的大小的功能。

I built a quiz game with a cartoon question bubble. The bubble is re sized to the length of the question. I want to a change event on the dynamic textbox to call a function that changes the size of the question bubble.

但是,更改事件不会被调用时,我的文本框的值是动态地从code修改。

However, the change event is never called when my textbox value is modified dynamically from code.

 question_txt.addEventListener(Event.CHANGE, setTextBubbleSize);

 function setTextBubbleSize(event:Event):void
	{
		trace("QUESTION TEXT CHANGED");
		textBubble_mc.height = 30 + question_txt.text.length * 1.2;
		if (textBubble_mc.height > 170) textBubble_mc.height = 170;
		question_txt.y = textBubble_mc.y - textBubble_mc.height / 6 + 10;
	}

我想使用更改事件,因为有几个地方在我的code表示question_txt可以设置。我怎样才能获得文本框火的change事件?

I want to use the change event because there are several places in my code that question_txt can be set. How can I get the textbox to fire the change event?

此外,有没有一种方法来计算question_txt行数更精确地设定textBubble_mc的高度?

Also, is there a way to count the number of lines in question_txt to more accurately set the height of textBubble_mc?

推荐答案

是的,大卫的意见,文本字段仅调度更改事件时,它正在编辑的用户输入 - 在事实上,这是一般最真实的组件。当然,究其原因,是因为如果你手动试图改变在你的变处理程序中的字段的值,你会做,你不得不手动检测你的出路事件的递归循环。

Yes, as David comments, TextField only dispatches CHANGE events when it's being edited by user input - in fact, this is generally true of most components. The reason, of course, is because if you manually tried to change the field's value inside your "change" handler, you'd make a recursive cycle of events that you'd have to manually detect your way out of.

您想要做的是做一个包装的功能,如:

What you want to do is make a wrapper function, like:

function setQuestionText( s:String ):void
    {
        question_txt.text = s;
        setTextBubbleSize();
    }

有关您的其他问题,也没有理由基于线条或字符数来估计文本框的高度 - 刚刚成立的文本属性,并可以立即查询该文本框的高度。它会准确地反映该领域的新高度,如果更改场的宽度,高度将立即进行更新,等等。

For your other question, there is no reason to estimate the textfield's height based on the number of lines or characters - just set the text property, and you can immediately query the textfield's height. It will accurately reflect the field's new height, and if you change the field's width, the height will immediately be updated, etc.

或者,如果你需要了解的文本字段的大小的任何细节,你可以随时使用<一个href="http://help.adobe.com/en%5FUS/AS3LCR/Flash%5F10.0/flash/text/TextExtent.html">TextExtent.

Or, if you need to know any fine details about the size of the text field, you can always use TextExtent.

这篇关于AS3文本框更改事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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