To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > General Help > XML

Reply
 
Thread Tools Search this Thread Display Modes
Old 06-22-2006, 04:05 AM   #1
realifreebie
Junior Member
 
Join Date: Jun 2006
Posts: 1
can help me with my flash xml loading?

i want to load a xml file very dynamically in flash. i have a xml file as blow:

<?xml version="1.0"?>

<cbs>

<employee>
<number>1</number>
<name>Shi Chuan</name>
<comment>intern</comment>
</employee>

<employee>
<number>1</number>
<name>Shang</name>
<comment>flasher</comment>
</employee>

<employee>
<number>2</number>
<name>Jakson</name>
<comment>rapist</comment>
</employee>

<employee>
<number>2</number>
<name>Charles</name>
<comment>director</comment>
</employee>

</cbs>


when i load it in flash, i hope flash can recognize the value between the <number> tag. and put them into two groups(number 1 one group, number 2 another group) according to their number. in this case, it should display:

1st group:

Shi Chuan
intern;
Shang
flasher

2nd group:

Jakson
rapist;
Charles
director


if i add one more node in xml like below:

<employee>
<number>1</number>
<name>John</name>
<comment>healer</comment>
</employee>


i hope flash can auto-update the info and display:

1st group:

Shi Chuan
intern;
Shang
flasher;
john
healer


2nd group:

Jakson
rapist;
Charles
director;
john
healer


don't know if you guys have any idea how to make it.
pls help me! thank you.
realifreebie is offline   Reply With Quote
Old 06-23-2006, 02:18 AM   #2
Chris_Seahorn
up to my .as in code
 
Chris_Seahorn's Avatar
 
Join Date: Dec 2004
Posts: 4,376
All of this assumes you use a number value of 1 or 2 as your posted xml suggests.

Here is a quick example that will at least show you how to dig out the nodes depending on what that number value is. In this I send all users with a value of "1" to one textfield and all with a value of "2" to the other textfield.

http://actionscript.hobby-site.com/e...s/freebie.html

It uses a flash movie with two textfields. One with an instance name of "txt1" and one with an instance name of "txt2". This puppy only needs one frame so post this in the actions for frame 1:

Code:
Group1 = new Array();
Group2 = new Array();

my_xml = new XML();
my_xml.load("./freebie.xml");
my_xml.ignoreWhite = true;
my_xml.onLoad = function(Success){
	if (Success){
           dissect();
		  
	}else{
		txt1.text= "xml error.";
	}
};
txt1.text="";
txt2.text="";								 
function dissect() {
i=0;
for (p=0; p<my_xml.firstChild.childNodes.length; p++) {
if(my_xml.firstChild.childNodes[p].childNodes[0].childNodes[0].nodeValue=="1"){
                 Group1.push(my_xml.firstChild.childNodes[i].childNodes[0].childNodes[0].nodeValue+"\n");
			    Group1.push(my_xml.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue+"\n");
			   Group1.push(my_xml.firstChild.childNodes[i].childNodes[2].childNodes[0].nodeValue+"\n");
			   i++;
			
				txt1.text = Group1;
			
			
			}else{
			 Group2.push(my_xml.firstChild.childNodes[i].childNodes[0].childNodes[0].nodeValue+"\n");
			    Group2.push(my_xml.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue+"\n");
			   Group2.push(my_xml.firstChild.childNodes[i].childNodes[2].childNodes[0].nodeValue+"\n");
			   i++;
	           txt2.text = Group2;
			
	}
	}
	}
	}
stop();
The freebie.xml file I used is just your original with me adding new ones from the backend that automatically show just like you requested:

Code:
<?xml version="1.0"?>

<cbs>

<employee>
<number>1</number>
<name>Shi Chuan</name>
<comment>intern</comment>
</employee>

<employee>
<number>1</number>
<name>Shang</name>
<comment>flasher</comment>
</employee>

<employee>
<number>2</number>
<name>Jakson</name>
<comment>rapist</comment>
</employee>

<employee>
<number>2</number>
<name>Charles</name>
<comment>director</comment>
</employee>

<employee>
<number>1</number>
<name>Chris</name>
<comment>XMLFreak</comment>
</employee>

<employee>
<number>2</number>
<name>Filipe</name>
<comment>Chef</comment>
</employee>

<employee>
<number>2</number>
<name>Pierre</name>
<comment>Bellhop</comment>
</employee>

</cbs>

This help?

Last edited by Chris_Seahorn; 06-23-2006 at 02:20 AM.
Chris_Seahorn is offline   Reply With Quote
Old 06-23-2006, 02:47 AM   #3
Chris_Seahorn
up to my .as in code
 
Chris_Seahorn's Avatar
 
Join Date: Dec 2004
Posts: 4,376
In that last reply I posted it sending the sections to an array since that is useful. If you were going to repurpose those sections later in the movie...the arrays would come into play.

You may however simply want to send the values concatenated to a html enabled textfield if you have no need for the arrays created and only want a simple display.

Instead of displaying the raw arrays we could maybe:

http://actionscript.hobby-site.com/e.../freebie2.html

by using this script on frame 1 and making both textfields html enabled:]

Code:
my_xml = new XML();
my_xml.load("./freebie.xml");
my_xml.ignoreWhite = true;
my_xml.onLoad = function(Success){
	if (Success){
           dissect();
		  
	}else{
		txt2.text= "xml error";
	}
};
txt1.htmlText="<u><b>Group 1 Users</b></u><br><br>";
txt2.htmlText="<u><b>Group 2 Users</b></u><br><br>";								 
function dissect() {
i=0;
for (p=0; p<my_xml.firstChild.childNodes.length; p++) {
if(my_xml.firstChild.childNodes[p].childNodes[0].childNodes[0].nodeValue=="1"){
               //in this example we drop the number from display since it's obvious
               	//txt1.htmlText += my_xml.firstChild.childNodes[i].childNodes[0].childNodes[0].nodeValue+"<br>";
			    	txt1.htmlText += "<b>"+my_xml.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue+"</b><br>";
			   	txt1.htmlText += my_xml.firstChild.childNodes[i].childNodes[2].childNodes[0].nodeValue+"<br>";
			   i++;
			
			
			
			
			}else{
		//in this example we drop the number from display since it's obvious
			 //txt2.htmlText += my_xml.firstChild.childNodes[i].childNodes[0].childNodes[0].nodeValue+"<br>";
			    txt2.htmlText += "<b>"+my_xml.firstChild.childNodes[i].childNodes[1].childNodes[0].nodeValue+"</b><br>";
			   txt2.htmlText += my_xml.firstChild.childNodes[i].childNodes[2].childNodes[0].nodeValue+"<br>";
			   i++;
	        
			
	}
	}
	}
	}
	stop();

Last edited by Chris_Seahorn; 06-23-2006 at 02:49 AM.
Chris_Seahorn is offline   Reply With Quote
Old 06-23-2006, 02:55 AM   #4
Chris_Seahorn
up to my .as in code
 
Chris_Seahorn's Avatar
 
Join Date: Dec 2004
Posts: 4,376
And fire that "Jackson" dude for gods sake...he's a rapist!
Chris_Seahorn is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > General Help > XML

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:50 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.