In dev stage :p

Started by
18 comments, last by ????????????? 12 years ago
http://www.flashwonderland.com/flash-actionscript-php-one-way-communication/as3-php-communication-12.html

I copied it exactly but happents nothing
Advertisement

http://www.flashwond...ication-12.html

I copied it exactly but happents nothing


1. You should not copy things exactly. That is not going to get you very far with learning much of anything. If you want to learn to draw, do you find a nice drawing and trace it? How many times of tracing until you can finally draw something without tracing it?

2. Are you running the php on a server? Did you verify that the URL is correct?

Here are some resources for you (by the magical powers of Google):

http://www.gamedev.n...ne-gaming-r2062
http://en.wikipedia....cryptography%29
http://hejp.co.uk/fl...et-programming/
http://playerio.com/...games-tutorial/
http://www.skullbox.net/tcpudp.php
https://developers.g....com/appengine/

The first link talks about security issues, the next a bit about salting and why it is important, the next deals with socket programming in flash, then a really long tutorial on building multiplayer games in flash, the next deals with the difference between TCP and UDP, and the last is a resource that is becoming popular for implementing backends for this type of project....

This is not an endorsement, you have a LONG way to go, but I will put this information in-case others need it.

If you read this one mostly: http://playerio.com/documentation/tutorials/building-flash-multiplayer-games-tutorial/ I think you will gain an appreciation for the amount of work your in for (at least 10% of the work your in for!)

Also I understand that this is a forum and we are not expected to write perfect English (and that many users do not speak English as their primary language), but could you please put a bit more effort into your posts? If possible please at least attempt to use capitalization, grammar, and avoid obvious spelling mistakes... It makes your posts hard to read and does not lend much credibility to what you have to say.
Yes, sorry but my first lang is greek and there is a huge difference, but i will be more carefull. Thank you for the tuts, be sure im gonna reade all! Now, about my code take a look yourself:



// define the PHP file that will be loaded
var phpFile:String = "heirosfiile.php";
//Create a URLLoader object with the name myLoader
var myLoader:URLLoader = new URLLoader();

//specify dataFormat property of the URLLoader to be "VARIABLES"
//This ensure that the variables loaded into Flash with the same variable names
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

function checkComplete(evt:MouseEvent):void {

// Create a new URLRequest object specifying the location or URL
// of the PHP file.
var urlRequest:URLRequest = new URLRequest(phpFile);

//Load the PHP file into the loader by using URLRequest
myLoader.load(urlRequest);

//Listen when the loading of PHP file COMPLETE
//Call the loadComplete function when the loading COMPLETE
myLoader.addEventListener(Event.COMPLETE, loadComplete);

}
// Hook up the button with the function loadFile
button.addEventListener(MouseEvent.CLICK, checkComplete);
function loadComplete(evt:Event){

// Display the value with variable name "Candidate"
textbox1.text = evt.target.data.Candidate;

//Display the value with variable name "Date"
textbox2.text = evt.target.data.Date;
}


The php is same as in the link i posted.
When something does not work as expected, the first tactic should be to debug it. In this case I would try a number of things:

1. Try putting string literals in the textbox1.text and textbox2.text fields in the loadComplete function (so like "test"). If you see those values then the problem would be that Candidate and Data are blank (which is likely).

You ARE running this on a server right? If you are trying to run it locally on your machine then it will not work. To do a test in your php file, try printing your values as well and loading the php page in a browser.

Try fully qualifying your URL path and see if that makes a difference as well...
I tryed it both on wamp (local) and on a server too. I will do these tests and i will tell you ;) Right now im making a test chat that Bacterius said and i think im on a good way BUT i have a tiny problem. Could i post my code here or its not permited?

Then how can i do it? For example, how i will pass the ingame name of the player from the database to the flash textbox or label?


The appropriate way is to:
1) Write a server application, preferably one capable of running in a distributed fashion (This depends on the complexity of the game itself, if the game is simple enough you can get away with 1 servermachine per world but most MMOs need more. (as an example WoW runs a few hundred servers per world) (This should be written as a standalone application, not as a webserver script)
2) Have the server application read the necessary data from the database and keep it in RAM while it is needed (cuts down on database access, don't use your database as a RAM replacement or your performance will suffer (Allthough some SQL databases do support memory mapped tables that are quite fast).
3) Have the flash client connect to the server using a socket.
4) Send and read data using the sockets, make your own game specific binary protocol for this and make sure it is as optimized as possible (For an MMO it is essential, you will have to handle thousands of concurrent players (MMO stands for massivly multiplayer online, not persistent online) so every byte counts. (and bandwidth is not cheap)
5) have the actionscript parse the data it reads from the socket and then use it appropriatly.


Using URL requests only really works for turnbased games(DreamWorld is an example of a turnbased MMO which works using this method) or slower games with a low number of concurrent players(not MMOs or even action heavy normal multiplayer games) but even for these games it is a sub optimal method to use which will greatly increase your bandwidth costs and thus make it alot harder to actually keep the game operational. (a simple test using wireshark and my own webserver showed that sending the word "test" using HTTP required 385 bytes. (The request for the document required 719 bytes)
Sending the same using raw sockets can be done using 5-6 bytes (a 1-2 byte "length" value + the 4 bytes for the text itself) and a 1-4 byte request.

If you use the var=value&var2=value2 syntax you'll also need at the very least 5-6(4-5 for the first value) bytes for each 1 byte value you wish to send, 5-8 bytes per 2 byte value and 5-13 per 4 byte value (unless you're sending floats, then the number of bytes required can get even higher) and to get that "low" overhead you'd have to restrict yourself to using single letter identifiers (Which will make your code a pain to work with)

the ~300 bytes of overhead(Just for the HTTP header), at an update rate of 10 times per second(a low update rate) and 3000 players (a small MMO) adds up to an extra 72Mbps bandwidth being used (on top of what you need for the things that are actually important or unavoidable(such as the TCP and IP headers).

if you send around 300 bytes worth of real data in each update you'll get at the very least another 100-400Mbps worth of unnecessary overhead due to the plain text transmission format. (If done badly you can end up with several Gbps overhead for a small (2000-3000 players) MMO, and that is only counting the upstream bandwidth from server to client, the overhead on data sent from clients to the server can be even worse.

Basically a MMO using HTTP will become prohibitivly expensive to host unless it is turnbased with very limited player interaction and even then the cost will be far higher than necessary. (HTTP really is a protocol that should have been dead allready, its not even suitable for normal websites anymore (But agreeing on a new standard for the web isn't trivial so it remains))
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Oh my god man i didnt understand anything!!! What are all these sockets, ram with server etc. I need a book for all these!

Oh my god man i didnt understand anything!!! What are all these sockets, ram with server etc. I need a book for all these!

You're going to need a lot more than just some books. Programming experience doesn't come magically by reading books, you need to take baby steps and eventually, after several weeks or months of looking at a problem, you will finally understand how to tackle it.

When I started programming I wanted to do a sudoku generator (not even solver, just generator). I spent days trying to find how it worked, how I could do it so that it would generate a sudoku in reasonable time. I just couldn't. I did not understand how to make it work, and I felt pretty stupid. So I kept working, trying different things, prototyping... Almost two months later it all clicked together and I "got it", and it was immensely satisfying. And that was just a tiny little problem which would probably take me very little time if I had to do it now - and not because I memorized how to do it years ago, but because I understand the concepts behind it.

Long story short, you need to slow down and actually go through the baby steps before trying to do MMO's or any other big project. This has been revisited countless times on the forums - just check out all the threads "I'm new to java/flash/html/you-name-it and want to make an MMO", etc... it does not work. There is no shame in starting with simple stuff, everybody who starts out a new subject/topic (it doesn't even have to be game design or even about computers) does exactly the same thing. But accepting that you need to learn by doing crappy chat applications or buggy pongs before being able to make an MMORPG is crucial.

Essentially, before being able to do A + B you need to be able to do A, and B. And the best way to do that is to do A and B separately (which is called prototyping!). Otherwise if you just tackle A + B directly you will end up struggling because of the complex relationships between A and B (i.e. changing something in A may require a complete rewrite of B which in turn may need you to redesign A), and you will waste more time refactoring code to accomodate your changes that actually working towards making A or B work. Not the best analogy - but I hope it makes sense.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


Oh my god man i didnt understand anything!!! What are all these sockets, ram with server etc. I need a book for all these!


RAM = random access memory, it is the memory you use to store data while it is being worked with. (all variables in your program use RAM to store its data), the alternative to storing things in RAM is to store it on disk (which is what a database does, unless it uses memory mapped tables or caching). reading data from disk is ALOT slower than accessing data you allready have loaded into RAM.

a Socket is what applications use to communicate with eachother, You open it and can send data through it which can then be read by whatever application is on the other side. (The URLRequests you've used thus far also use sockets behind the scenes but restrict you to loading text, documents or other files over the extremely verbose HTTP protocol rather than simply sending and recieving data)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Here is my chat code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.test {
text-align: center;
}
</style>
</head>
<body class="test">
<script type="text/javascript">
function display()
{
<?php
@ $text = $_POST['textfield'];
$db = new mysqli("localhost", "triplew_test", "1qw21qw2", "triplew_test");
$query = "insert into chat values ('', 'guest : ', '".$text."')";
?>
document.form1.textarea.value = <?php echo $text; ?>
}
</script>



<form id="form1" name="form1" method="post" onSubmit="display()">
<p>
<textarea name="textarea" cols="45" rows="20" readonly="readonly" id="textarea"></textarea>
</p>
<p>
<input type="text" name="textfield" id="textfield" />
</p>
<input name="go" type="submit" value="GO!" />
</form>
</body>
</html>

This topic is closed to new replies.

Advertisement