Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-04-2007, 09:27 AM   #1
pasteur
Obsesif Kompulsif Kisilik
 
pasteur's Avatar
 
Join Date: Feb 2006
Location: Istanbul
Posts: 37
Send a message via MSN to pasteur
Wink XML loop problem

I am having trouble with an xml loop. Here is my xml structure:

Code:
<myxml>
	<item>
		<name>Name 01</name>
		<id>ID 01</id>
		<colors>
			<color>white</color>
			<color>red</color>
		</colors>
		<width>100</width>
	</item>
	<item>
		<name>Name 02</name>
		<id>ID 02</id>
		<colors>
			<color>blue</color>
			<color>purple</color>
			<color>black</color>
			<color>brown</color>
		</colors>
		<width>100</width>
	</item>	
</myxml>
Here is my "onload" function for this xml:

Code:
function xmlload() {
	item = this.firstChild.childNodes;
	num = item.length;
	xplacering = 0;
	for (var i:Number = 0; i < num; i++) {
		itemname = item[i].firstChild.firstChild.nodeValue;
		itemid = item[i].firstChild.nextSibling.firstChild.nodeValue;
		itemcolors = ???// i need to attach mc's for "colors"..
		itemwidth = item[i].firstChild.nextSibling.nextSibling.nextSibling.firstChild.nodeValue;
		// attaching mc for each item
		mymc = attachMovie("mymc", "mymc" + i, i);
		mymc._y = 0;
		xplacering = xplacering + mymc._width + 5;
		mymc._x = xplacering;
	}
}
There is no problem with item numbers.. I can attach movies for all, and i can trace name, id etc.. for each item.

But the problem is, i can't reach to colors.. I need to attach movies for each
color in every item.

I mean, i need to attach 2 movies for item named "Name 01" ( of course, i need to trace the color names ) and 4 movies for item named "Name 02" ( again trace the color names ).. I think it's easy but i am really confused. I will be pleased for any help.
pasteur is offline   Reply With Quote
Old 02-04-2007, 09:51 AM   #2
aeon
Visit aendirect.com
 
aeon's Avatar
 
Join Date: May 2003
Location: Singapore
Posts: 104
Send a message via MSN to aeon Send a message via Skype™ to aeon
Default

I didn't really understand your question but here's how I would parse the colors. Putting the colors in multidimensional array each referencing a single "item" containing another array of all the colors.

Also cleaned up the tree-walking code for clarity.
I hate siblings.siblings.siblings....

Code:
function xmlload() {

	var item:xmlNode = this.firstChild.childNodes;
	var num:Number = item.length;
	var xplacering:Number = 0;
	var itemColors:Array = new Array();

	for (var i:Number = 0; i < num; i++) {

		itemname = item[i].childNode[0].firstChild.nodeValue;
		itemid = item[i].childNode[1].firstChild.nodeValue;

		var itemColors[i]:Array = newArray();
		// Loop through all colors and shove them into an array
		for (var numColors:Number = 0; numColors < item[i].childNode[1].childNodes.length, numColors++) {
			itemColors[i][numColors] = item[i].childNode[1].childNode[numColors].nodeValue;
		}

		itemwidth = item[i].childNode[3].firstChild.nodeValue;
		// attaching mc for each item
		mymc = attachMovie("mymc", "mymc" + i, i);
		mymc._y = 0;
		xplacering = xplacering + mymc._width + 5;
		mymc._x = xplacering;

	}
}
Example: 4th color of 2nd item

Code:
itemColors[1][3]

Last edited by aeon; 02-04-2007 at 10:08 AM.
aeon is offline   Reply With Quote
Old 02-04-2007, 11:19 AM   #3
pasteur
Obsesif Kompulsif Kisilik
 
pasteur's Avatar
 
Join Date: Feb 2006
Location: Istanbul
Posts: 37
Send a message via MSN to pasteur
Default

var itemColors[i]:Array = new Array();

this line gives Syntax Error.. ?

if i drop "[i]" it accepts but does nothing.
pasteur is offline   Reply With Quote
Old 02-04-2007, 04:12 PM   #4
pasteur
Obsesif Kompulsif Kisilik
 
pasteur's Avatar
 
Join Date: Feb 2006
Location: Istanbul
Posts: 37
Send a message via MSN to pasteur
Default

i am still trying.. i don't want to get older because of this problem..
pasteur is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird Infinate Loop Problem KWarp ActionScript 2.0 2 10-04-2006 05:16 AM
nested loop problem Marianne Other Flash General Questions 1 09-12-2006 06:30 PM
Loop, SetInterval problem. Fred_J ActionScript 2.0 19 08-19-2006 10:29 PM
Player 8 Install Loop Problem? apprentice Flash 8 General Questions 0 03-20-2006 09:27 PM
loop problem jimmyo ActionScript 1.0 (and below) 6 02-28-2005 08:57 PM


All times are GMT. The time now is 10:28 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.