Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:21:56+00:00 2026-06-08T12:21:56+00:00

I have a flash game. I want to send my score to the database

  • 0

I have a flash game. I want to send my score to the database by .php. How can i do that? I have written some posts but i couldn’t figure it out how. What should i do in actionscript 3 side and php side? my database name is my_db and my variable is _score.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:21:57+00:00Added an answer on June 8, 2026 at 12:21 pm

    First you need to create an URLLoader and store the variables you want to send into the header of the request.
    After loading the URL and sending the variables we listen for the COMPLETE event so we can get variables from PHP back to Flash.

    ActionScript 3 Code:

    private function SendScore(score:int) {
        //Use URLVariables Class to store our Variables and send them to our URL
        var variables:URLVariables = new URLVariables();
        //you can create as many variables you want (variables.variablename);
        variables.score = score;
        //URLLoader to load the URL
        var urlloader:URLLoader = new URLLoader;
        //Simple URLRequest with our URL
        var urlrequest:URLRequest = new URLRequest('http://www.mysite.com');
        //We set the method to POST. You can also use GET
        urlrequest.method = URLRequestMethod.POST;
        //We declare our set of variables to the data of our urlrequest
        urlrequest.data = variables;
    
        //We load the URL           
        urlloader.load(urlrequest);
        //We need to listen to an Event.COMLETE when we want to load variables FROM PHP
        urlloader.addEventListener(Event.COMPLETE, CompleteHandler, false, 0, true);
        //With  the listening to IOErrorEvent.IO_ERRORwe can intercept an error and can use it for Debugging
        urlloader.addEventListener(IOErrorEvent.IO_ERROR , ErrorHandler, false, 0, true);
    }
    
    //CompleteHandler will be used when the Load of the URL is completed
    private function CompleteHandler(e:Event) {
        //Received Variables from PHP script
        var vars:URLVariables = new URLVariables(e.target.data);
        //You can access all variables from PHP with vars.xxxx
        //Example: vars.var1, vars.var2
        if(vars.success) trace('Saving succeeded');
        else ('Saving failed');
    }
    
    //ErrorHandler to receive error messages and don't fire exception errors
    private function ErrorHandler(e:IOErrorEvent) {
        trace('Error occured');
    }
    

    In PHP we receive the variables with the method POST from Flash and can use them with $_POST[‘xxx’]. We insert the score into a database and we check if the INSERT was a success or not and send this variable back to the “browser”/Flash.

    PHP Code (I’m using PDO for database operations: http://php.net/manual/de/book.pdo.php):

    try {
        //Establishing database connection with PDO
        $DB = new PDO($dsn, $user, $pw, array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));
    } catch (PDOException $e) {
        //Error catching
        print "Connection to Database failed: " . $e->getMessage() . "<br />";
        die();
    }
    
    //Create a SQL statement, prepare it and execute it to INSERT the data into database
    //the "variables.score" from AS3 can be read with $_POST['score'], cause we used POST as method
    $sql = "INSERT INTO my_db (is_score) VALUES ('".$_POST['score']."');";
    $stmt = $DB->prepare($sql);
    $stmt->execute();
    
    //Here we send back a variable to AS3:
    //If you want to send more variables back use the & sign to append more variables
    //example: 'succeds=true&var1=this&var2=there'
    //Can be read in CompleteHandler with vars.success
    if($stmt->rowCount() > 0) echo('success=true');
    else echo('success=false');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a game loop written in Haxe/Flash. For some reason it slows down
I have a flash based game that has a high score system implemented with
I have a swf file (a flash game). I want to run some script
suppose I want to make a Flash browser game that can be played in
In my isometric flash game I have some models with long shadows. I want
I have a flash movie that runs fine in FF, Opera, Safari but not
I have a flash player that loads in some additional features from flash files
I'm making a game in flash, and I want to have a whole bunch
I have a game made by Flash CS5 ActionScript3. I want to create a
I have a game and I used Flash cs5 ActionScript3. I want to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.