mardi 14 février 2017

Flash AS3 <-> PHP via POST failing outside of Flash Professional

After some researching, it seems this is a pretty popular problem. Unfortunately, none of the previously-answered questions have been able to solve this particular issue I am facing.

So, first things first, The Setup:

  1. I have a personal web server, accessible externally via http, henceforth referred to as the webserver.
  2. The webserver is capable of servicing php requests.
  3. I have a php script, henceforth referred to as the php.
  4. The php parses a POST request, and uses the data send to update a MySQL database, also hosted on the webserver, that is henceforth referred to as the database.
  5. I use a select command on the webserver, connected to remotely using PuTTy, to check the rows that the php affects, in a process henceforth referred to as checking for changes.
  6. I have a Flash project, created in Adobe Flash Professional CS6, using AS3, henceforth referred to as the Flash.
  7. The Flash creates a POST request, sent to the php, in a process henceforth referred to as the transmission. The transmission is properly formatted, and has been vetted to make sure that it is being interpreted by the php correctly and is making the appropriate changes to the database.
  8. The Flash is published with "Access network only" set. Changing it does not seem to make a difference, however.

Now with that being said, here is The Code.

Note that I have changed the url in the code below to point to a bogus web-server. I have also changed the database connection information to be similarly bogus. The rest of the structure is correct, however, including folder-structure and file-name:

Flash (Code.DataTransmitter):

public function SendData():void {
    var myData:URLVariables = new URLVariables();

    myData.update = "true";
    myData.score_humans = MasterManager.gameManager.scoreHumans;
    myData.score_creatures = MasterManager.gameManager.scoreCreatures;

    var myRequest:URLRequest = new URLRequest(""); = myData;
    myRequest.method = URLRequestMethod.POST;

    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, OnSendDataComplete);

    try {
    } catch (error:Error) {
        trace ('Error: unable to load the document.');

public function OnSendDataComplete(e:Event):void {



if (isset($_POST['update'])) {
    $dbhost = '';
    $dbuser = 'bogususer';
    $dbpass = 'boguspassword';

    $mysqli = new mysqli($dbhost, $dbuser, $dbpass, 'test_game_table', 3306);

    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") "  . $mysqli->connect_error;

    $score_humans = intval( $_POST['score_humans'] );
    $score_creatures = intval( $_POST['score_creatures'] );

    if ($score_humans >= 0 && $score_creatures >= 0) { // Error-check: No negative values
        $strquery = "update stats";

        $strquery .= " set score_humans = score_humans + " . $score_humans;
        $strquery .= ", score_creatures = score_creatures + " . score_creatures;

        $strquery .= " where id = 1";

        $strquery = $mysqli->real_escape_string($strquery); // Even though it should be clean, sanitize it anyways.


        echo "received=true";

echo "Hello there!";


And now, finally, The Problem.

It's really a simple problem, that probably doesn't deserve this much preamble, but I believe in getting all of the information out and disambiguated first, to reduce the amount of questions needed before solutions can be proposed.

  1. When I run the Flash in Flash Professional, the database is properly updated - checking for changes correctly returns the changes that are being sent.
  2. When I run the Flash (or more accurately, the published html wrapper) in Google Chrome on the hard-disk (being addressed with file:///), the database is NOT properly updated - checking for changes returns that no changes were made, when there should have been changes made.
  3. When I run the Flash in Google Chrome, hosted from the same web-server as the php (more precisely,, the database is NOT properly updated.

Put more concisely, the request only seems to work correctly when sent through Flash Professional - when sent through Google Chrome, it fails in some capacity.

I would really appreciate any assistance in solving this problem.

Thank you in advance!

Aucun commentaire:

Enregistrer un commentaire