ActionScript 2.0 - 匹配轨迹实际上并不匹配

发布于 2024-12-06 21:32:24 字数 1180 浏览 1 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尽揽少女心 2024-12-13 21:32:24

Selection.getFocus() 使用 eval()

Use eval() for the Selection.getFocus()

她说她爱他 2024-12-13 21:32:24

如果您不想使用 eval(),则另一种选择是 坏名声,要获得与 Selection.getFocus() 返回相同类型的字符串表示形式,可以使用 "" + m_InputFieldsArray[i].textField。它不会像 toString() 那样返回“[Object object]”。

这基本上就是您在跟踪调用中看到的内容,与对象引用连接的字符串给出了对象的路径,而不是对象上的 .toString() 。

我现在无法测试 AS2,但我很确定它就是这样工作的。所以你可以这样做:

if (Selection.getFocus() == "" + m_InputFieldsArray[i].textField) 

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]", as toString() 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:

if (Selection.getFocus() == "" + m_InputFieldsArray[i].textField) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文