webForumDet fria alternativet

duplicateMovieClip-problem

Flash

2 svar · 173 visningar · startad av oskob

Medlem sedan maj 20021 558 inlägg
Frågan#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!

Medlem sedan maj 2003750 inlägg
#2

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

Medlem sedan maj 20021 558 inlägg
#3

Åh... Mein gut.
Klantigt klantigt.
Tack så mycket!
Hade tagit dagar för mig att upptäcka :)

248 ms totalt · 4 externa anrop · v20260731065814-full.e96017d9
124 ms — deklarationer (db)
0 ms — hämta statistik (cache)
121 ms — hämta tråd, inlägg och bilagor (db)
124 ms — ändringar (db)