2011-09-28 22 views
0

(主帮助我在AS2编程)的ActionScript 2.0 - 匹配痕迹实际上并不匹配

我正在itterating通文本字段对象的数组和压片当跟踪被选定的关注领域,以及每个对象。

我试图将这些对象等同起来,但是当它们追踪完全相同时,它们不是。

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]

我该如何完成匹配?

+0

'm_TitleTextInput'和其他组件? –

+0

是的,他们是定制的Scaleform组件。 – TheDarkIn1978

回答

1

使用eval()Selection.getFocus()

+0

对,John Giotta!非常感谢! – TheDarkIn1978

1

的选择,如果你不想使用eval(),具有bad reputation,要得到同样的字符串表示Selection.getFocus的()返回时,你可以使用"" + m_InputFieldsArray[i].textField。它不会返回“[Object object]”,如toString()所做的那样。

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

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

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