Actionscript 3 AS3:通过引用对象的名称获取对象的值
我正在阅读XML并将值附加到两个单独的movieclips中的对象。像这样Actionscript 3 AS3:通过引用对象的名称获取对象的值,actionscript-3,object,Actionscript 3,Object,我正在阅读XML并将值附加到两个单独的movieclips中的对象。像这样 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的值进行比较,
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";
}
}
你有个打字错误。Map02使用标记1事物。 如果是Stackoverflow中的输入错误 这个.getChildByName(“Marker01”)将返回movieclip,购买它的名称。不过要小心,因为它搜索的是“名称”。当您应该将Marker01作为名称时,您使用了“hello there”。我建议您放置一个名为“data”的属性,并将xml信息放在其中,这样就不会发生冲突 最后你有: if(this.getChildByName(“Marker01”).data.value==this.getChildByName(“Marker02”).data.value) 我假设这是因为您在运行时生成Marker0X,并且不能声明一些变量并直接使用它们
如果将“数据”作为自定义类的实例,在其中可以比较两个“数据”,则会出现棕色点。如果需要更多帮助,请添加注释^ ^Map01和Map02是MovieClips,每个MC包含一个对象标记01。是吗?是的!这些物体也是MCs。呃,我真的不明白。还有,打字错误。我做了一个简化的样品,应该能对这件事有更多的了解。。好吧,如果我能想出如何发布它$%%&%$&