ActionScript 2.0 - 匹配轨迹实际上并不匹配
(上帝帮助我在 AS2 中编程)
我正在迭代一系列文本字段对象,并在按下 Tab 时跟踪选定的焦点字段以及每个对象。
我试图将这些对象等同起来,但是虽然它们追踪完全相同,但它们却并非如此。
m_InputFieldsArray = new Array(m_TitleTextInput, m_CommentsTextArea, m_EmailTextInput);
for (var i:Number = 0; i < m_InputFieldsArray.length; i++)
{
trace("Get Focus: " + Selection.getFocus());
trace("Arr Index: " + m_InputFieldsArray[i].textField);
if (Selection.getFocus() == m_InputFieldsArray[i].textField)
{
trace("Match!");
return;
}
else
{
trace("NO Match!");
}
}
输出:
Get Focus: _level0.m_Window.form.m_TitleTextInput.textField
Arr Index: _level0.m_Window.form.m_TitleTextInput.textField
NO Match!
Get Focus: _level0.m_Window.form.m_TitleTextInput.textField
Arr Index: _level0.m_Window.form.m_CommentsTextArea.textField
NO Match!
Get Focus: _level0.m_Window.form.m_TitleTextInput.textField
Arr Index: _level0.m_Window.form.m_EmailTextInput.textField
NO Match!
第一组跟踪相同,但显然它们不匹配。 Selection.getFocus()
返回一个字符串,而数组索引则跟踪文本字段对象。如果我将 toString()
添加到文本字段对象,它将跟踪为 [Object object]
我如何完成匹配?
(lord help me for programming in AS2)
i'm itterating thru an array of text field objects and tracing the selected focus field when pressing tab, as well as each object.
i'm trying to equate these object, but while they trace the exact same they are not.
m_InputFieldsArray = new Array(m_TitleTextInput, m_CommentsTextArea, m_EmailTextInput);
for (var i:Number = 0; i < m_InputFieldsArray.length; i++)
{
trace("Get Focus: " + Selection.getFocus());
trace("Arr Index: " + m_InputFieldsArray[i].textField);
if (Selection.getFocus() == m_InputFieldsArray[i].textField)
{
trace("Match!");
return;
}
else
{
trace("NO Match!");
}
}
the output:
Get Focus: _level0.m_Window.form.m_TitleTextInput.textField
Arr Index: _level0.m_Window.form.m_TitleTextInput.textField
NO Match!
Get Focus: _level0.m_Window.form.m_TitleTextInput.textField
Arr Index: _level0.m_Window.form.m_CommentsTextArea.textField
NO Match!
Get Focus: _level0.m_Window.form.m_TitleTextInput.textField
Arr Index: _level0.m_Window.form.m_EmailTextInput.textField
NO Match!
the first group traces the same, but apparently they do not match. Selection.getFocus()
returns a string, while the array index is tracing the text field object. if i add toString()
to the text field object it will trace as [Object object]
how can i accomplish a match?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对
Selection.getFocus()
使用eval()
Use
eval()
for theSelection.getFocus()
如果您不想使用 eval(),则另一种选择是 坏名声,要获得与 Selection.getFocus() 返回相同类型的字符串表示形式,可以使用
"" + m_InputFieldsArray[i].textField
。它不会像toString()
那样返回“[Object object]”。这基本上就是您在跟踪调用中看到的内容,与对象引用连接的字符串给出了对象的路径,而不是对象上的 .toString() 。
我现在无法测试 AS2,但我很确定它就是这样工作的。所以你可以这样做:
An alternative, if you don't want to use eval(), that has a bad reputation, to get the same kind of string representation as Selection.getFocus() returns, you can use
"" + m_InputFieldsArray[i].textField
. It won't return "[Object object]", astoString()
does.That is basically what you see in your trace calls, that a string concatenated with the object reference gives the path to the object, rather than .toString() on the object.
I can't test AS2 right now, but I'm pretty sure that is how it works. So you could do something like this: