---
title: "duplicateMovieClip-problem"
type: "forum-thread"
url: "https://www.webforum.nu/amne/flash/131599-duplicatemovieclip-problem"
topic: "Flash"
topic_url: "https://www.webforum.nu/amne/flash"
author: "oskob"
published: "2005-07-19T11:40:58.000Z"
updated: "2005-07-19T11:51:33.000Z"
replies: 2
views: 184
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/flash/131599-duplicatemovieclip-problem"
---

# duplicateMovieClip-problem

## #1 — oskob, 2005-07-19T11:40Z

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!

Permalänk: https://www.webforum.nu/p/131599

## #2 — mirandir, 2005-07-19T11:46Z

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

Permalänk: https://www.webforum.nu/p/1647081

## #3 — oskob, 2005-07-19T11:51Z

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

Permalänk: https://www.webforum.nu/p/1647083

---

Tråden på webben: https://www.webforum.nu/amne/flash/131599-duplicatemovieclip-problem
