2013-06-03 75 views
0

我正在讀取XML並將值附加到兩個單獨的影片剪輯中的對象。像這樣AS3:通過引用其名稱獲取對象的值

Map01: 
Marker01.name = hello there 
Marker01.short = hel 
Marker01.value = 12 

Map02: 
Marker02.name = hello there 
Marker02.short = hel 
Marker02.value = 99 

現在我單擊Map01中的Marker01並獲取其名稱和值。我想將它的值與Map02中Marker01的值進行比較,使用名稱,或者更好.short,因爲名稱很長並且使用特殊字符/空格。我該怎麼做呢?我幾乎嘗試了一切似乎合乎邏輯的事情!


編輯:澄清

var marker01:mc_marker = new mc_marker(); 
marker01.name="hello there"; 
marker01.short="abc"; 
marker01.val="99"; 
marker01.x=10; 
marker01.y=10; 
this.mc_map01.addChild(marker01); 

var marker02:mc_marker = new mc_marker(); 
marker02.name="hello there"; 
marker02.short="abc"; 
marker02.val="20"; 
marker02.x=10; 
marker02.y=10; 
this.mc_map02.addChild(marker02); 

marker01.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo); 
marker02.addEventListener(MouseEvent.MOUSE_UP, showMarkerInfo); 

function showMarkerInfo(event:MouseEvent):void { 
    txt_ms.text=event.target.short; 
    txt_mv.text=event.target.val; 
    if (event.target.short==mc_map02.marker02.short){ 
     txt_mvi.text="here should be the marker02 value"; 
    } 
} 
+0

Map01和Map02是動畫片段,每個MC都包含一個Object Marker01。是對的嗎? – McMannus

+0

是的!對象也是MC。 – CodeBunny

回答

0

示例代碼你有一個錯字那裏。 Map02使用Marker1的東西。 如果在拼寫錯誤中存在拼寫錯誤,請使用this.getChildByName(「Marker01」)將影片剪輯返回給您,購買其名稱。儘管如此,因爲「名稱」是它搜索的內容。當您應該將Marker01作爲名稱時,您使用了「你好」。我建議你把一個名爲「數據」的屬性,並把它的XML信息,所以它不衝突。如果(this.getChildByName(「Marker01」).data.value == this.getChildByName(「Marker02」).data.value)。

我認爲這是因爲您在運行時生成Marker0X,並且無法直接聲明某些變量並使用它們。

如果您將「數據」設置爲可以比較兩個「數據」的自定義類的實例,則爲布朗點。如果您需要更多幫助,請添加評論^ _^

+0

呃,我真的不明白這一點。還有,錯字。我做了一個簡化的樣本,應該更清楚地說明問題..好,如果我能弄清楚如何發佈它$%$&%$& – CodeBunny