oskob Medlem sedan maj 2002 1 558 inlägg Frågan 19 juli 2005 11:40 #1 Hejsan!
Den här koden ingår i en loop som loopar igenom en xml-fil men den vill bara duplicera movieclipet en gång och sen ersätter den bara innehållet.
Får inga felmeddelanden.
img_container.duplicateMovieClip("img_container"+post_id, post_id);
_root["img_container"+post_id].lead.text = lead;
_root["img_container"+post_id].body.text = body;
_root["img_container"+post_id].address.text = address;
_root["img_container"+post_id].attrib.text = attrib;
_root["img_container"+post_id]._y = 10*post_id;
post_id += 1;
Här är resten av koden om ni vill se sammanhanget:
xmlData = new XML();
xmlData.onLoad = myLoad;
xmlData.load("headlines.xml");
function myLoad(ok) {
if (ok == true) {
Publish(this.firstChild);
}
}
function Publish(xmlDataNode) {
if (xmlDataNode.nodeName.toUpperCase() == "BROADCAST") {
content = "";
story = xmlDataNode.firstChild;
while (story != null) {
if (story.nodeName.toUpperCase() == "STORY") {
lead = "";
body = "";
address = "";
attrib = "";
post_id = 1;
element = story.firstChild;
while (element != null) {
if (element.nodeName.toUpperCase() == "LEAD") {
lead = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "BODY") {
body = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "URL") {
address = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "ATTRIB") {
attrib = element.firstChild.nodeValue;
}
element = element.nextSibling;
}
content += "<font size='+2' color='#3366cc'><a href='"+address+"'>"+lead+"</a></font><br>"+body+"<br>"+attrib+"<br><br>";
txt.htmlText = content;
[b]
img_container.duplicateMovieClip("img_container"+post_id, post_id);
_root["img_container"+post_id].lead.text = lead;
_root["img_container"+post_id].body.text = body;
_root["img_container"+post_id].address.text = address;
_root["img_container"+post_id].attrib.text = attrib;
_root["img_container"+post_id]._y = 10*post_id;
post_id += 1; [/b]
}
story = story.nextSibling;
}
}
}
Tack på förhand!
M mirandir Medlem sedan maj 2003 750 inlägg Flytta raden:
post_id = 1;
Till att vara före while-loopen:
while (story != null) {
Annars återställs den ju till 1 vid varje iteration.
function Publish(xmlDataNode) {
if (xmlDataNode.nodeName.toUpperCase() == "BROADCAST") {
content = "";
story = xmlDataNode.firstChild;
[b]post_id = 1;[/b]
while (story != null) {
if (story.nodeName.toUpperCase() == "STORY") {
lead = "";
body = "";
address = "";
attrib = "";
element = story.firstChild;
while (element != null) {
if (element.nodeName.toUpperCase() == "LEAD") {
lead = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "BODY") {
body = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "URL") {
address = element.firstChild.nodeValue;
}
if (element.nodeName.toUpperCase() == "ATTRIB") {
attrib = element.firstChild.nodeValue;
}
element = element.nextSibling;
}
content += "<font size='+2' color='#3366cc'><a href='"+address+"'>"+lead+"</a></font><br>"+body+"<br>"+attrib+"<br><br>";
txt.htmlText = content;
img_container.duplicateMovieClip("img_container"+post_id, post_id);
_root["img_container"+post_id].lead.text = lead;
_root["img_container"+post_id].body.text = body;
_root["img_container"+post_id].address.text = address;
_root["img_container"+post_id].attrib.text = attrib;
_root["img_container"+post_id]._y = 10*post_id;
post_id += 1;
}
story = story.nextSibling;
}
}
}
/Mirandir
oskob Medlem sedan maj 2002 1 558 inlägg Åh... Mein gut.
Klantigt klantigt.
Tack så mycket!
Hade tagit dagar för mig att upptäcka :)