ActionScript 3.0 文本输入和显示
我是flash新手,下面是我的脚本,我有3个文本输入框,name1,name2,name3和3个动态文本,output1,output2,output3。用户在框中输入文本后,它应该在动态输出文本中显示完全相同。它适用于第一个,但不适用于第二个和第三个。我以不同的方式重命名了更改处理程序以消除编译错误,但现在只有第一个有效。如果我想要多个文本框主菜,有更好的方法吗?
name1.addEventListener(Event.CHANGE, changeHandler);
function changeHandler(e:Event):void
{
output1.text = name1.text
}
name2.addEventListener(Event.CHANGE, changeHandler);
function changeHandler1(e:Event):void
{
output2.text = name2.text;
}
name3.addEventListener(Event.CHANGE, changeHandler);
function changeHandler2(e:Event):void
{
output3.text = name3.text;
}
I am new at flash, the below is my script, i have 3 textinput boxes, name1, name2, name3 and 3 dynamic texts, output1, output2, output3. Once the user, enters the text in the box, it should appear exactly the same in the dynamic output text. It works for the first one, but does not work for the second and third one. I renamed changehandlers differently to remove compile errors, but now only the first one works. Is there a better way of doing this, if i want to have multiple textbox entrees?
name1.addEventListener(Event.CHANGE, changeHandler);
function changeHandler(e:Event):void
{
output1.text = name1.text
}
name2.addEventListener(Event.CHANGE, changeHandler);
function changeHandler1(e:Event):void
{
output2.text = name2.text;
}
name3.addEventListener(Event.CHANGE, changeHandler);
function changeHandler2(e:Event):void
{
output3.text = name3.text;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您忘记在后两个
addEventListener()
调用中更改侦听器函数的名称。它当前对所有三个事件调用changeHandler()
。您应该:
您可以创建一个类来管理连接输入文本字段与输出文本字段:
现在您可以循环遍历文本字段并使用以下方法连接它们:
You forgot to change the name of the listener functions in the latter two
addEventListener()
calls. It currently callschangeHandler()
on all three events.You should have:
You can create a class that manages joining the input text field with the output text field:
And now you can loop through your text fields and join them using this: