Forum Topic: As: Xml For Online Interactivity

(3,807 views • 54 replies)

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

<< < > >>
None

Khao

Reply To Post Reply & Quote

Posted at: 10/18/05 04:54 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

ONE THREAD TO RULE THEM ALL!

You may need to read this thread to understand how to work with XML before starting, but I will still explain XML just a little less : AS: XML by Inglor

Ok, so you want to have interactivy and multiplayer online with flash? Well first you need a server! www.nowcentral.com is the one I use.
Install it, then launch it (start > programs > nowserver > launch nowserver)
Now that this is done, to the flash part!

To be able to connect to a server and send/receive XML data you need a socket
mySocket = new XMLSocket();

Then you need to tell the socket what to do when it successfully connects
mySocket.onConnect = function(success){ //success will be true or false
if(success){
//actions when you successfully log
}else{
//actions when you fail to log
}

Then, you need actions to do when the socket loses connection or when you close the connection
mySocket.onClose=function(){
//actions to do
}

Then, you need actions to do when the socket receives data
mySocket.onData = function(data){//data contains what the received XML object contained in a string
data = new XML(data);//converts the string to an XML object (easier to work with)
}

now, you need to connect to a server
mySocket.connect("localhost",5525)//"local
host" is your own IP, else you can enter the IP of the server you want to connect to, 5525 is the port number, it is the default port of nowserver

now, if you want to send XML objects trough that socket
mySocket.send(myXML);

ok that is for everything that has to do with the server, but since this is working with XML objects, you need to learn how to work with them AS: XML by Inglor
just a little something to complete Inglor's tutorial(cause i didnt saw that in his tut), to create an XML object in flash instead of importing one from a file, write your XML in a var.

ex : myXML = '<level id='1' name="Forest of Home>'
myXML = new XML(myXML)

now myXML is an XML object that you can send trough a socket

please post anything to complete this thread, comments and suggestions here

-Steven


None

Denvish

Reply To Post Reply & Quote

Posted at: 10/18/05 04:59 PM

Denvish DARK LEVEL 42

Sign-Up: 04/25/03

Posts: 15,933

Good job. I really need to get into XML at some point, online multiplayer would be excellent (though probably a nightmare to code). This should act as a nice complimentary thread to Inglor's for people interested in XML.

- - Flash - Music - Report Abuse - -
Not around any more, see last news post.

BBS Signature

None

Khao

Reply To Post Reply & Quote

Posted at: 10/18/05 05:01 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

At 10/18/05 04:59 PM, Denvish wrote: Good job. I really need to get into XML at some point, online multiplayer would be excellent (though probably a nightmare to code). This should act as a nice complimentary thread to Inglor's for people interested in XML.

yep its a nightmare cause ive had problems having a correct user list, making it so it doesnt lag, and all these things, but works great for chatrooms and little thingies :)


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/18/05 05:03 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

When I put in "localHost" it works but when I put in my IP it doesnt
Why?

- Matt, Rustyarcade.com


None

Khao

Reply To Post Reply & Quote

Posted at: 10/18/05 05:04 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

At 10/18/05 05:03 PM, Ninja-Chicken wrote: When I put in "localHost" it works but when I put in my IP it doesnt
Why?

did you write it like this : connect("xx.xx.xx.xx",5525) ?


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/18/05 05:05 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

At 10/18/05 05:04 PM, -KhAo- wrote:
At 10/18/05 05:03 PM, Ninja-Chicken wrote: When I put in "localHost" it works but when I put in my IP it doesnt
Why?
did you write it like this : connect("xx.xx.xx.xx",5525) ?

Yeah

mySocket = new XMLSocket();
mySocket.connect("XX.XXX.XX.X", 5525);
mySocket.onConnect = function(success) {
if (success) {
trace("HH");
} else {
}
};

- Matt, Rustyarcade.com


None

BleeBlap

Reply To Post Reply & Quote

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

BleeBlap LIGHT LEVEL 24

Sign-Up: 03/08/05

Posts: 945

If you are behind a firewall the server will not be able to be accessed remotely. In english this means if there is more than one computer in the house connected to the same internet connection or if you have wireless internet you have a router. This means when the request gets sentout over the internet it gets sent from your ISP (internet service provider) back to your router which doesn't know what to do about it unless you mess with the router configuration. So putting localhost doesn't send it out over the internet and it works but using the isp does and it doesn't work. To fix it you can just unplug everybody else's internet and connect directly or set up the router which is different for each one and you should probably refer to the manual.


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/18/05 05:09 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

Yeah I was just about to say its probally my router :P
Well this means I can only test this out when I go to my dads :P

- Matt, Rustyarcade.com


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/18/05 05:12 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

Okay can you post an example of how we might make a chat room or something (just so I can see it all in use)

- Matt, Rustyarcade.com


None

Khao

Reply To Post Reply & Quote

Posted at: 10/18/05 05:15 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

At 10/18/05 05:12 PM, Ninja-Chicken wrote: Okay can you post an example of how we might make a chat room or something (just so I can see it all in use)

oh yeah you make me think

lTHERE ARE A LOT OF EXAMPLES OF CHATROOMS WITHING THE NOWSERVER FOLDER
here, boldenised so all of you can see
i dont want to post my chatroom cause im lazy


None

Denvish

Reply To Post Reply & Quote

Posted at: 10/18/05 05:18 PM

Denvish DARK LEVEL 42

Sign-Up: 04/25/03

Posts: 15,933

Hmmm, I have a router too =(
Bummer. Sure I should be able to figure out how to config it though.
Will these restrictions only apply while authoring the Flash, or will it affect anybody who has a router and is viewing the swf in a browser?

- - Flash - Music - Report Abuse - -
Not around any more, see last news post.

BBS Signature

None

Inglor

Reply To Post Reply & Quote

Posted at: 10/18/05 05:21 PM

Inglor NEUTRAL LEVEL 17

Sign-Up: 01/26/03

Posts: 10,957

so that's why you bugged me with all these XMLSocket questions, lol, good work :D


None

Khao

Reply To Post Reply & Quote

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

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

At 10/18/05 05:18 PM, Denvish wrote: Hmmm, I have a router too =(
Bummer. Sure I should be able to figure out how to config it though.
Will these restrictions only apply while authoring the Flash, or will it affect anybody who has a router and is viewing the swf in a browser?

people viewing the .swf with a router should be able to connect to a server with his IP if the server is not behind a router itself


None

Denvish

Reply To Post Reply & Quote

Posted at: 10/18/05 05:28 PM

Denvish DARK LEVEL 42

Sign-Up: 04/25/03

Posts: 15,933

At 10/18/05 05:24 PM, -KhAo- wrote: people viewing the .swf with a router should be able to connect to a server with his IP if the server is not behind a router itself

Another question: does the (online) server have to be of a specific variety that supports XML sockets, or will any web-based domain work? I have several domains that I run websites on, are those useable for this kind of activity (bandwidth considerations aside)?

- - Flash - Music - Report Abuse - -
Not around any more, see last news post.

BBS Signature

None

Khao

Reply To Post Reply & Quote

Posted at: 10/18/05 05:32 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

At 10/18/05 05:28 PM, Denvish wrote:
At 10/18/05 05:24 PM, -KhAo- wrote: people viewing the .swf with a router should be able to connect to a server with his IP if the server is not behind a router itself
Another question: does the (online) server have to be of a specific variety that supports XML sockets, or will any web-based domain work? I have several domains that I run websites on, are those useable for this kind of activity (bandwidth considerations aside)?

i dont think you can make it without a flash server like nowserver ( www.nowcentral.com )
so if you have any server you could install it on them and get the industrial version for BIG multiplayer cause the low version can only handle 5 users


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/18/05 05:33 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

here is a code I threw together to see it work but for some reason it doesnt
It connects but doesnt send/receive data anyone have any ideas as to why?

mySocket = new XMLSocket();
mySocket.onData = function(data) {
//data contains what the received XML object contained in a string
data = new XML(data);
trace (data)
//converts the string to an XML object (easier to work with)
};
myXML = "<level id='1' name=\"Forest of Home>";
myXML = new XML(myXML);
mySocket.connect("localhost", 5525);
mySocket.onConnect = function(success) {
if (success) {
trace ("HIT")
mySocket.send(myXML);
} else {
}
};

- Matt, Rustyarcade.com


None

Denvish

Reply To Post Reply & Quote

Posted at: 10/18/05 05:34 PM

Denvish DARK LEVEL 42

Sign-Up: 04/25/03

Posts: 15,933

At 10/18/05 05:32 PM, -KhAo- wrote: i dont think you can make it without a flash server like nowserver ( www.nowcentral.com )
so if you have any server you could install it on them and get the industrial version for BIG multiplayer cause the low version can only handle 5 users

OK, thanks for taking the time to respond.

Twenty more questions later ;D

- - Flash - Music - Report Abuse - -
Not around any more, see last news post.

BBS Signature

None

fwe

Reply To Post Reply & Quote

Posted at: 10/18/05 05:37 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,372

NC, dont convert it to an xml object when recieving, it already is one

wtfbbqhax


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/18/05 05:39 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

At 10/18/05 05:37 PM, fwe wrote: NC, dont convert it to an xml object when recieving, it already is one

oh well -KhAo- said to...
Do you know whats wrong with the code above?
And also what kind of format is the data received in (for example how do I get that id number out of the data when its received)

- Matt, Rustyarcade.com


None

Khao

Reply To Post Reply & Quote

Posted at: 10/18/05 05:42 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

At 10/18/05 05:37 PM, fwe wrote: NC, dont convert it to an xml object when recieving, it already is one

its a string -_-
try using firstchild or nodename on the received data without doing new XML...

and also i forgot to say this but, with nowserver your xml objects needs to start with

<?xml version="1.0"?>

and in the variables that you send you need to put a "user" var and a "channel" var... example

myXML = '<?xml version="1.0"?><Chat><Info channel="channel1" user="' add username add '" data=" HAS LOGGED IN" /></Chat>'

sorry that i forgot to say this
anyway, im off now if you need anymore help try to look in the examples from nowserver (i mostly learned all from that) or ill answer back later


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/18/05 05:49 PM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

Excellent thanks
My question still remains though for example:
myXML = "<?xml version=\"1.0\"?><Chat><Info channel=\"channel1\" user=\" add username add \" data=\" HAS LOGGED IN\" /></Chat>";
how do I access the "channel" part of that when it is received

- Matt, Rustyarcade.com


None

fwe

Reply To Post Reply & Quote

Posted at: 10/18/05 06:09 PM

fwe DARK LEVEL 08

Sign-Up: 07/24/03

Posts: 3,372

At 10/18/05 05:42 PM, -KhAo- wrote:
At 10/18/05 05:37 PM, fwe wrote: NC, dont convert it to an xml object when recieving, it already is one
its a string -_-
try using firstchild or nodename on the received data without doing new XML...

and also i forgot to say this but, with nowserver your xml objects needs to start with

<?xml version="1.0"?>

No it doesn't.
Don't use on data, use onXML, make it a function too

socket.onXML =parseXML
function parseXML(node) {
trace(socket.nodeName == "level") {
trace(node.attributes.id)
trace(node.atributes.name)
}
//You also need a loop here to cycle through all the messages recieved at once
//Just use the one nowserver made
if (node.hasChildNodes()) {
node = node.firstChild;
parseXML(node);
node = node.nextSibling;
while (node != null) {
parseXML(node);
node = node.nextSibling;
}
}
}
}

wtfbbqhax


None

Khao

Reply To Post Reply & Quote

Posted at: 10/18/05 06:29 PM

Khao EVIL LEVEL 19

Sign-Up: 09/20/03

Posts: 2,767

thanks for the tip fwe you pwn :)


None

BleeBlap

Reply To Post Reply & Quote

Posted at: 10/18/05 07:25 PM

BleeBlap LIGHT LEVEL 24

Sign-Up: 03/08/05

Posts: 945

At 10/18/05 05:28 PM, Denvish wrote: Another question: does the (online) server have to be of a specific variety that supports XML sockets, or will any web-based domain work? I have several domains that I run websites on, are those useable for this kind of activity (bandwidth considerations aside)?

Like Khao said at this point it does require a special server however with the Flash player 8.5 thing I saw a little while ago it will support binary sockets which would let you not only send custom data types more concisely and quickly but binary servers (read most) will be compatible with it too. That whole thread is here.


None

SpamBurger

Reply To Post Reply & Quote

Posted at: 10/18/05 07:54 PM

SpamBurger NEUTRAL LEVEL 15

Sign-Up: 07/12/05

Posts: 4,620

Meh, too complicated for me.

Good job though :)

"However, the game received only two orders, one of which Molyneux speculated was from his mother." -Peter Molyneux's first game The Entrepreneur


None

hashbrown

Reply To Post Reply & Quote

Posted at: 10/18/05 08:00 PM

hashbrown LIGHT LEVEL 16

Sign-Up: 07/07/05

Posts: 3,036

im glad im not an actionscripter i have to learn this stuff. blee blap tryed to teach me how to tween with as and i didnt get it. the only things i need to know is storyboard control. asing must suck huh?^^


None

Glaiel-Gamer

Reply To Post Reply & Quote

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

Glaiel-Gamer NEUTRAL LEVEL 26

Sign-Up: 12/28/04

Posts: 7,063

At 10/18/05 08:00 PM, -hashbrown- wrote: blee blap tryed to teach me how to tween with as

onClipEvent(enterFrame){
_x += 5
}


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/19/05 04:14 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

Yes this is so cool. I made a little chat room : )
I will post it later when I get off work and figure out how to reconfigure my router

- Matt, Rustyarcade.com


Happy

unownedJR

Reply To Post Reply & Quote

Posted at: 10/19/05 04:27 AM

unownedJR NEUTRAL LEVEL 16

Sign-Up: 06/10/03

Posts: 2,335

Cool, I suck at AS and I have a long way to go before I hit XML, but at least now I have a head's up on it, thanks a lot -Khao- =D

By the way, wouldn't you need a fast server with a high refresh rate to make something like stick RPG?


None

Rustygames

Reply To Post Reply & Quote

Posted at: 10/19/05 07:41 AM

Rustygames LIGHT LEVEL 18

Sign-Up: 05/07/05

Posts: 6,429

Okay I have 20 mins of my lunch break left so can someone add me on msn and try out my chatroom with me. It requires that you download the server and use it on your computer - I will explain how to do everything and it only takes 2 mins so please help me out : )
Thanks

- ninjachicken@hotmail.co.uk

- Matt, Rustyarcade.com


All times are Eastern Standard Time (GMT -5) | Current Time: 11:42 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!