Forum Topic: As: Xml

(4,287 views • 53 replies)

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
None

Inglor

Reply To Post Reply & Quote

Posted at: 6/30/05 11:18 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

AS: Main

XML is a very good and importent way to work with external data in flash, it's easy, implented and efficient to save levels, maps, and data in general. I will cover the basics of loading XML and processing it here.

First we learn XML
There really isn't much to learn about xml, there are no commands or anything, it's a way of storing data. we start with the type we're saving for example level, then we put the attributes followed by the data. for example here is what I used. remmember, every tag we open we close.

<level id='1' name="Forest of Home>

</level>

there , I created a new level, now let's pour some data in, there are 2 ways of storing data in xml, like this:

<data id=1 />

no need to close the tag, we gave it an attribute and it's one

and

<data>1</data>

this is the other way, I ususally preffer the first way, this tutorial isn't about teaching xml, so if you're interested in actual xml this is an excellent tutorial

opening an xml file

The first thing we need to do is open the xml file we're parsing, for this tutorial i'm using the following file

<data>
<Message text="Welcome to Godlimation" />
<Message text="Site Created By Inglor" />
<Message text="This site belongs to Patrick, creator of Xunmato" />
<Message text="Visit our new link section" />
<Message text="The user system, is N/A yet" />
<Message text="Mo likes to touch little kids" />
<Message text="David and Goliath, coming soon" />

</data>

this is an XML document I've created somewhat not too long ago for a site I'm working on, it's named "data.xml".

now let's open it in flash, the first thing we need to do is create a new XML handler object

this is done the following:

Messages=new XML();

I named it Messages, I could have picked any other name.

the second thing we must do is clear out all the white spaces, this is very importent since that way our data is clean and " "s in our XML are ignored.

this is done the following:

Messages.ignoreWhite = true;

the next thing we need to do is load the actual xml file into flash, this is done with the load command,

Messages.load('data.xml');

now we have an XML object handler with all the XML data inside it, all we have to do now is process it.

Parsing the XML

now messages has several "childs", these are the contents of him

Messages.onLoad = function(success) {
if (success) {
readMessages();
}
};

every time you open a XML file always include a onLoad function, this is what triggers when the XML loads

my read messages function is the following

Messages.onLoad = function(success) {
if (success) {
readMessages();
}
};
function readMessages(){
_root.a=new Array();
for(i=0;Messages.firstChild.childNodes[i]!=undefined;i++){
base=Messages.firstChild.childNodes[i].attributes.text;
trace(base);
_root.a.push(base);
}
_root.delay=0;
_root.onEnterFrame=function():Void{
if(_root.delay==0){
this.message=this.a[random(this.a.length)];
_root.delay=60;
}
_root.delay-=_root.delay>0;
}
}

I will explain the terms now
for(i=0;Messages.firstChild.childNodes[i]!=undefined;i++){
this runs untill the node of the first child (which are the <message> tags since they are nodes of the <data> tag) is undefined meaning, untill thre are no more messages to read.

base=Messages.firstChild.childNodes[i].attributes.text;

the firstChild is data, the child node is the current message, now attributes are the data, and text is the attribute I'm addressing (since it's text="blablabla" in the XML file)
trace(base);
_root.a.push(base);

and I trace it and push it into a data array, now after the loop ends I have all my data in the array and I'm free to process it ;)

Hope this tutorial contributed, I know it's kinda confusing, please ask any questions.

Learn XML
the flash XML faq
Useful Resource
XML tutorials


None

T-H

Reply To Post Reply & Quote

Posted at: 6/30/05 11:21 AM

T-H LIGHT LEVEL 39

Sign-Up: 01/07/04

Posts: 4,893

I like it, I've heard about XML (external markup lang right?), but never learnt any. Would this be useful for making scoreboards?


None

Dancing-Thunder

Reply To Post Reply & Quote

Posted at: 6/30/05 11:25 AM

Dancing-Thunder NEUTRAL LEVEL 04

Sign-Up: 04/19/05

Posts: 278

At 6/30/05 11:21 AM, T-H wrote: I like it, I've heard about XML (external markup lang right?), but never learnt any. Would this be useful for making scoreboards?

For scoreboards, I think you have to use PhP.


None

Inglor

Reply To Post Reply & Quote

Posted at: 6/30/05 11:26 AM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

extendable markup language

this isn't very useful for scoreboards (SQL databases are better at that since you don't have to load data into flash but just send it.) but it is VERY GOOD AND VERY IMPORTENT at hight levels, for example, multiplayer games are done through XML sockets, and it's very good to load level maps using it, and it works great with php for loading and setting external live data. XML is quick too :)


None

Denvish

Reply To Post Reply & Quote

Posted at: 6/30/05 12:19 PM

Denvish DARK LEVEL 46

Sign-Up: 04/25/03

Posts: 16,236

At 6/30/05 11:25 AM, Dancing-Thunder wrote:
At 6/30/05 11:21 AM, T-H wrote: I like it, I've heard about XML (external markup lang right?), but never learnt any. Would this be useful for making scoreboards?
For scoreboards, I think you have to use PhP.

Or ASP. Both of the Overrun scoreboards are pulled from MS Access databases through ASP pages. Basically the same principle as MYSQL/PHP, just slightly different procedures and coding.

I have also never really touched upon XML, never really had the need to, but I think it's probably time to get to grips with it.

- - Flash - Music - Images - -

BBS Signature

None

Inglor

Reply To Post Reply & Quote

Posted at: 6/30/05 12:21 PM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,948

yea, the thing is ASP servers ususally cost money where there are plenty MySQL+PHP free hosts ;)

but yea, nothing wrong with ASP and ASPX

XML is really useful, you should use it for your site ;) a bunch of cool stuff can be accomplished with it


None

Creepy

Reply To Post Reply & Quote

Posted at: 10/24/05 11:08 AM

Creepy EVIL LEVEL 07

Sign-Up: 11/28/04

Posts: 1,241

can u use XML to make massive multiplayer online games?


None

Creepy

Reply To Post Reply & Quote

Posted at: 10/24/05 03:31 PM

Creepy EVIL LEVEL 07

Sign-Up: 11/28/04

Posts: 1,241

At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?

*bump*

=D


None

Toast

Reply To Post Reply & Quote

Posted at: 10/24/05 03:45 PM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,918

At 10/24/05 03:31 PM, Creeepy wrote:
At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?
*bump*

=D

Lol, don't expect to be making a massive multiplayer game before years of experience :P


None

Creepy

Reply To Post Reply & Quote

Posted at: 10/24/05 03:49 PM

Creepy EVIL LEVEL 07

Sign-Up: 11/28/04

Posts: 1,241

At 10/24/05 03:45 PM, -Toast- wrote:
At 10/24/05 03:31 PM, Creeepy wrote:
At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?
*bump*

=D
Lol, don't expect to be making a massive multiplayer game before years of experience :P

=P no, i wasnt acctually hoping to get a finished script right in my hand!!
i was just wondering, cuz then i would maybe study on XML so i can be able to make this type of games in some years :)


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/24/05 05:08 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

At 10/24/05 03:45 PM, -Toast- wrote:
At 10/24/05 03:31 PM, Creeepy wrote:
At 10/24/05 11:08 AM, Creeepy wrote: can u use XML to make massive multiplayer online games?
*bump*

=D
Lol, don't expect to be making a massive multiplayer game before years of experience :P

Dont expect to do that for years because flash is currently too shit

- Matt, Rustyarcade.com


None

Khao

Reply To Post Reply & Quote

Posted at: 10/24/05 05:45 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,765

At 10/24/05 05:08 PM, Ninja-Chicken wrote:
At 10/24/05 03:45 PM, -Toast- wrote:
Lol, don't expect to be making a massive multiplayer game before years of experience :P
Dont expect to do that for years because flash is currently too shit

mhmm... wait a sec... isnt that what is coming???

shit have I said too much... or not enough?

None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/24/05 05:47 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,662

At 10/24/05 05:45 PM, -KhAo- wrote:
At 10/24/05 05:08 PM, Ninja-Chicken wrote:
At 10/24/05 03:45 PM, -Toast- wrote:
Lol, don't expect to be making a massive multiplayer game before years of experience :P
Dont expect to do that for years because flash is currently too shit
mhmm... wait a sec... isnt that what is coming???
shit have I said too much... or not enough?

??? What
Dude your not going to be able to make a massivly multiplayer game because flash is too weak to handle it

- Matt, Rustyarcade.com


None

Khao

Reply To Post Reply & Quote

Posted at: 10/24/05 05:54 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,765

At 10/24/05 05:47 PM, Ninja-Chicken wrote:
??? What
Dude your not going to be able to make a massivly multiplayer game because flash is too weak to handle it

it could rip your head apart if only it wanted to!


None

Rammer

Reply To Post Reply & Quote

Posted at: 10/24/05 05:57 PM

Rammer DARK LEVEL 32

Sign-Up: 06/08/03

Posts: 4,331

At 10/24/05 05:54 PM, -KhAo- wrote:
At 10/24/05 05:47 PM, Ninja-Chicken wrote:
??? What
Dude your not going to be able to make a massivly multiplayer game because flash is too weak to handle it
it could rip your head apart if only it wanted to!

i think ive seen some flash-based MMORPGs...

snyggys


None

Khao

Reply To Post Reply & Quote

Posted at: 10/24/05 06:03 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,765

At 10/24/05 05:57 PM, 2k_rammerizkool wrote:
i think ive seen some flash-based MMORPGs...

me too


None

Fire

Reply To Post Reply & Quote

Posted at: 11/18/05 05:47 PM

Fire DARK LEVEL 15

Sign-Up: 10/29/03

Posts: 2,935

Is there a way to spread XML nodes to AS variables? Like:

<stuff>
<this>Hi</this>
<that name="Something">Somethng Aweful</that>
</stuff>

would be:

this="Hi"
name="Something"
that="Something Aweful"


None

Claxor

Reply To Post Reply & Quote

Posted at: 11/20/05 01:45 PM

Claxor DARK LEVEL 10

Sign-Up: 10/21/05

Posts: 2,465

Does loading exernal XML files require that the .swf and the XML file is on the same domain?

BBS Signature

None

Ptcfast

Reply To Post Reply & Quote

Posted at: 1/10/06 08:33 PM

Ptcfast FAB LEVEL 12

Sign-Up: 01/07/06

Posts: 4,460

wow

BBS Signature

None

Hooked-ON-Phoneix

Reply To Post Reply & Quote

Posted at: 1/10/06 08:39 PM

Hooked-ON-Phoneix NEUTRAL LEVEL 03

Sign-Up: 01/02/06

Posts: 14

yes


None

Khao

Reply To Post Reply & Quote

Posted at: 1/10/06 08:42 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,765

At 11/20/05 01:45 PM, Claxor wrote: Does loading exernal XML files require that the .swf and the XML file is on the same domain?

no, go take a look at AS:Main and find the tutorial on cross-domain by Denvish


None

Neashir

Reply To Post Reply & Quote

Posted at: 1/10/06 08:42 PM

Neashir NEUTRAL LEVEL 18

Sign-Up: 08/08/05

Posts: 1,401

At 1/10/06 08:33 PM, invaderzig1 wrote: wow
At 1/10/06 08:39 PM, Hooked_ON_Phoneix wrote: yes

Both of you noobs trying to get your post count up, fuck off. We don't need your spam.


None

Thomas

Reply To Post Reply & Quote

Posted at: 1/10/06 09:26 PM

Thomas LIGHT LEVEL 13

Sign-Up: 02/14/05

Posts: 2,833

At 1/10/06 08:42 PM, Neashir wrote: Both of you noobs trying to get your post count up, fuck off. We don't need your spam.

Look who's spamming.

Nice XML tutorial Inglor :)

^to stay on topic^

None

Starogre

Reply To Post Reply & Quote

Posted at: 6/25/06 04:40 PM

Starogre NEUTRAL LEVEL 18

Sign-Up: 05/08/04

Posts: 1,701

Cool. How would you go about creating and appending xml files in flash?

BBS Signature

None

mynamewontfitin

Reply To Post Reply & Quote

Posted at: 6/25/06 05:15 PM

mynamewontfitin NEUTRAL LEVEL 19

Sign-Up: 09/01/03

Posts: 4,104

Awesome tutorial. Although I'm still a little confused with parsing the XML with the childs, nodes, etc.


None

suppi

Reply To Post Reply & Quote

Posted at: 2/27/07 04:51 PM

suppi LIGHT LEVEL 07

Sign-Up: 06/29/03

Posts: 119

ive played mmorpgs in flash if im not mistaken (tactics arena online)


None

adam2510

Reply To Post Reply & Quote

Posted at: 5/4/08 11:10 AM

adam2510 EVIL LEVEL 13

Sign-Up: 10/02/05

Posts: 3,721

At 6/30/05 11:18 AM, Inglor wrote: Hope this tutorial contributed, I know it's kinda confusing, please ask any questions.

how do i Write to xml in flash without php?

Web Hosting: Free! Premium!

BBS Signature

None

El-Presidente

Reply To Post Reply & Quote

Posted at: 5/4/08 11:15 AM

El-Presidente LIGHT LEVEL 27

Sign-Up: 06/02/05

Posts: 5,187

At 5/4/08 11:10 AM, adam2510 wrote: how do i Write to xml in flash without php?

Stop. Bumping. Old. Threads.
Just make a new topic. Also, XML isn't even necessary, it's just one way to send information to a server. On the other end I don't really know, but I'm pretty sure the tutorial explains it. Next time just make a new topic.

MY E-PENIS IS BIGGER THAN YOURS
8=================================>
...and this is my fag...

BBS Signature

None

GustTheASGuy

Reply To Post Reply & Quote

Posted at: 5/4/08 11:23 AM

GustTheASGuy LIGHT LEVEL 08

Sign-Up: 11/02/05

Posts: 11,376

At 5/4/08 11:10 AM, adam2510 wrote: how do i Write to xml in flash without php?

The programming forum devoted two thread pages explaining to you that you CAN'T. If you could then I would have long since overwritten your hard drive. Get the idea?

#ngprogramming at irc.freenode.net
haXe | Keel imperative | Spyro! | Thru you


None

Hoeloe

Reply To Post Reply & Quote

Posted at: 7/14/08 07:46 AM

Hoeloe LIGHT LEVEL 28

Sign-Up: 04/29/04

Posts: 5,014

I have code exactly like the one you posted, but for some reason, whatever I try, Flash runs the function last, I used the debugger to find this. This means that I can't actually use what's I'm defining in an Array, which makes this all useless. What can I do?

Sex!
------------------------------
Super Nuke Bros. Melee, the web's no. 1 awaited Super Smash Tribute Game!

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 06:32 AM

<< Back

This topic is 2 pages long. [ 1 | 2 ]

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!