all groups > flash data integration > november 2005 >
You're in the

flash data integration

group:

dynamic xml creation


dynamic xml creation mixey18
11/30/2005 8:52:29 PM
flash data integration:
How can I make XML dynamically inside tha Flash using AS?
Basicly i need to make structure like these one:
<root>
<item></item>
...
<item></item>
</root>

That's is the code i'm using:
var doc:XML = new XML("<root></root>");
var item:XMLNode = doc.createElement("item");
doc.firstChild.appendChild(item);
trace(doc);
------------
output:
<root><item /></root>
------------

And now the question, how can i add as many as i need item nodes?
please help me, i can't get over it!
Re: dynamic xml creation Motion Maker
11/30/2005 11:29:17 PM
Text nodes are optional to show something is happening.

var doc:XML = new XML("<root></root>");
var item:XMLNode = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 1") )
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 2") )
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 3") )
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 4") )
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 5") )
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 6") )
doc.firstChild.appendChild(item);
trace (doc)


--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
How can I make XML dynamically inside tha Flash using AS?
Basicly i need to make structure like these one:
<root>
<item></item>
...
<item></item>
</root>

That's is the code i'm using:
var doc:XML = new XML("<root></root>");
var item:XMLNode = doc.createElement("item");
doc.firstChild.appendChild(item);
trace(doc);
------------
output:
<root><item /></root>
------------

And now the question, how can i add as many as i need item nodes?
please help me, i can't get over it!

Re: dynamic xml creation FlashCuriouz
12/13/2005 1:19:59 PM
Re: dynamic xml creation Motion Maker
12/13/2005 2:01:00 PM
Undefined could mean that the var doc is not in scope or never assigned.

1. I created a new Flash Movie in Flash 8. Should work in MX 2004

2. On frame one I pasted the code
var doc:XML = new XML("<root></root>");
var item:XMLNode = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 1") );
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 2") );
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 3") );
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 4") );
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 5") );
doc.firstChild.appendChild(item);
item = doc.createElement("item");
item.appendChild(doc.createTextNode("Item 6") );
doc.firstChild.appendChild(item);
trace (doc);
3. Control->Test Movie display in output:

<root><item>Item 1</item><item>Item 2</item><item>Item 3</item><item>Item
4</item><item>Item 5</item><item>Item 6</item></root>


You could also do this and get same results:

myXml_str = "<root><item>Item 1</item><item>Item 2</item><item>Item
3</item><item>Item 4</item><item>Item 5</item><item>Item 6</item></root>";

var doc:XML = new XML(myXml_str);
trace (doc);
--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
This traces undefined for me. What am I missing?

AddThis Social Bookmark Button