2011-09-28 68 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)