我正在阅读XML并将值附加到两个单独的动画片段中的对象中。喜欢这个
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中使用名称或更好的.short将其值与Marker01的值进行比较,因为名称很长并且使用特殊字符/空格。我该怎么做呢?我几乎尝试了所有看似合乎逻辑的东西!
编辑:澄清的示例代码
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 :(得分:0)
你有一个错字。 Map02使用Marker1的东西。 如果它是Stackoverflow中的拼写错误,
this.getChildByName(“Marker01”)会返回你的movieclip,买它的名字。请注意,因为“名称”是它搜索的内容。当你把Marker01作为名字时,你用“你好那里”。我建议你放一个名为“data”的属性并将xml信息放入其中,这样就不会发生冲突。
最后你有: if(this.getChildByName(“Marker01”)。data.value == this.getChildByName(“Marker02”)。data.value)。
我认为这是因为你在运行时生成Marker0X而你不能声明一些变量并直接使用它们。
Browny指出,如果您将“数据”设为自定义类的实例,您可以在其中比较两个“数据”。如果您需要更多帮助,请添加评论^ _ ^