Flash - Actionscript if ... else 语句
我有一个基本的动作脚本代码,它基本上根据文本框的值显示一个列表。
if (txtValue.text = "0")
{
lstFilm.visible = false;
}
else if (txtValue.text = "1")
{
lstFilm.visible = true;
}
我遇到的问题是它不是改变列表的可见性,而是改变框中的值。有什么想法为什么或如何实现这一目标吗?
I have a basic actionscript code which basically shows a list depending on the value of a text box.
if (txtValue.text = "0")
{
lstFilm.visible = false;
}
else if (txtValue.text = "1")
{
lstFilm.visible = true;
}
The problem i'm having with it is instead of it changing the visibility of the list, it changes the value in the box. Any ideas why or how I could achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
==
,它是相等运算符而不是=
赋值运算符。Use
==
which is the equality operator not=
the assignment operator.if 语句通常需要评估“true”或“false”操作。
通过使用:
您实际上将值“0”分配给文本字段的“text”属性 - 换句话说,您不检查它是否等于“0”。
您必须使用双等于运算符来返回所需的结果:
然后这将正确地通过您的语句。
只有极少数情况下,您会希望在 if 语句中进行赋值(而不是“检查”条件)。这通常可以在文件读取或引用检查语句中找到,如下所示:
但这种方法有点令人不悦。对于初学者来说,更建议首先掌握“==”运算符。
An if statement typically needs to evaluate a 'true' or 'false' operation.
By using:
You are actually assigning the value "0" to the 'text' property of your textfield - In other words you are NOT checking if it is EQUALS-TO "0".
You have to use the double-equals operator to return the desired outcome:
This will then pass through your statement correctly.
Only some rare cases, you will wish to do an assignment (instead of 'checking' a condition) within the if-statement. This can often be found in file-reading or reference-checking statements like the following:
But this method is a bit frown upon. And for beginners it is much more recommended to master the "==" operator first.