Be a Supporter!

As: Xml For Online Interactivity

  • 5,457 Views
  • 53 Replies
New Topic Respond to this Topic
Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
As: Xml For Online Interactivity Oct. 18th, 2005 @ 04:54 PM Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 04:59 PM Reply

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 - Images - -

BBS Signature
Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:01 PM Reply

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 :)

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:03 PM Reply

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


- Matt, Rustyarcade.com

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:04 PM Reply

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) ?

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:05 PM Reply

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

BleeBlap
BleeBlap
  • Member since: Mar. 8, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:08 PM Reply

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.

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:09 PM Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:12 PM Reply

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

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:15 PM Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:18 PM Reply

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 - Images - -

BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:21 PM Reply

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

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:24 PM Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:28 PM Reply

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 - Images - -

BBS Signature
Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:32 PM Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:33 PM Reply

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

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:34 PM Reply

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 - Images - -

BBS Signature
fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:37 PM Reply

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


wtfbbqhax

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:39 PM Reply

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

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:42 PM Reply

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

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 05:49 PM Reply

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

fwe
fwe
  • Member since: Jul. 24, 2003
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 06:09 PM Reply

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

Khao
Khao
  • Member since: Sep. 20, 2003
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 06:29 PM Reply

thanks for the tip fwe you pwn :)

BleeBlap
BleeBlap
  • Member since: Mar. 8, 2005
  • Offline.
Forum Stats
Member
Level 24
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 07:25 PM Reply

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.

hashbrown
hashbrown
  • Member since: Jul. 7, 2005
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 08:00 PM Reply

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?^^


BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to As: Xml For Online Interactivity Oct. 18th, 2005 @ 08:24 PM Reply

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

onClipEvent(enterFrame){
_x += 5
}

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 19th, 2005 @ 04:14 AM Reply

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

unownedJR
unownedJR
  • Member since: Jun. 10, 2003
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to As: Xml For Online Interactivity Oct. 19th, 2005 @ 04:27 AM Reply

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?


the flash on this account isn't mine

Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to As: Xml For Online Interactivity Oct. 19th, 2005 @ 07:41 AM Reply

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

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to As: Xml For Online Interactivity Oct. 19th, 2005 @ 07:44 AM Reply

How do you detect a hitTest, for example, between two "players"?


BBS Signature