A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Highscore list using Flash and PHP

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    27

    Highscore list using Flash and PHP

    Hallo,

    I want to make a highscorelist using AS3 and PHP(MySQL).
    I cant find a good tutorial on internet how to make something but I got this so far:

    Actionscript Code:
    import fl.controls.TextInput;
    import fl.controls.TextArea;
    var variables:URLVariables = new URLVariables();
    variables.name = "Wil";
    variables.final = 2000;
     
    var request:URLRequest = new URLRequest();
     
    ////insert in the location of the php script ////////////////
    request.url = "http://www.justenter.nl/script.php";
    //////////////////////////////////////////////////////////////
     
    request.data = variables;
    var loader:URLLoader = new URLLoader();
     
    loader.load(request); //sends the request
     
    //when the request is done loading, it goes to the completeWriting function
    loader.addEventListener(Event.COMPLETE, completeWriting);
     
    function completeWriting(event:Event):void {
        var writingCompleted:TextField = new TextField;
        writingCompleted.autoSize = "center";
        writingCompleted.x =200;
        writingCompleted.y= 200;
        writingCompleted.text = event.target.data;
        addChild(writingCompleted);
     
    }

    He is sending the score and name to the database but he is doing that when i press ctrl-enter. He is sending the date I have put in:


    Actionscript Code:
    variables.name = "Wil";
    variables.final = 2000;

    I want a input textfield and a button. And When I fill in my name in the input textfield he send it to the database when I press the button.
    Is there someone that can help me out?

    Tnx

  2. #2
    Not Real since 1985
    Join Date
    Feb 2002
    Location
    Netherlands
    Posts
    229

    hiscore as3/php

    In as3 I use:
    Actionscript Code:
    private function checkAndSendData():void
    {
        if (_inputName.text.length < 4)
            return;
        var request:URLRequest = new URLRequest(url);
        var requestVars:URLVariables = new URLVariables();
        requestVars.name = _inputName.text;
        requestVars.score = _score;

        request.data = requestVars;
        request.method = URLRequestMethod.POST;
       
        urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
       
        urlLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler, false, 0, true);
       
        try {
            urlLoader.load(request);
        }
        catch (e:Error) {
            trace(e);
        }
    }

    private function loaderCompleteHandler(e:Event):void
    {
        var responseVars = URLVariables(e.target.data);
       
        for (var i:int = 0; i < 20; i++)
        {
            // do something with responseVars[];
            var myNumber:String = responseVars["nr" + i.toString()];
        }
    }
    Some pieces of PHP
    PHP Code:
    $name $_POST['name'];
    $score $_POST['score'];
    (...)
    $query1 "SELECT name, score FROM ".$tabel." ORDER BY score ASC, name LIMIT 20";
    $result1 mysql_query($query1,$dbh) OR die($query1.mysql_error());
    $i 0;
    print 
    "begin=1&";
    while (
    $hrow mysql_fetch_array($result1))
    {
        print 
    "nr".$i."=".$hrow["name"]."&pnt".$i."=".$hrow["score"]."&";
        
    $i++;
    }
    print 
    "end=1"
    If it is about more than a littlebit of data I prefer xml instead of one long line of data.
    Never accept the first 'impossible' unless it comes from a lady.

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    27
    Hi,

    Tnx for sharing! But I allready fixed it:-D but I got one last question.

    Now I can Post info in my database and can get it back too...

    But the scores that are in my flash are like this on stage:

    Here are all the flash scores in our database: name1=Wilfinal1=2000name2=Test
    final2=1234name3=Zzyzxfinal3=1000name4=Testfinal4= 1000name5=Peterfinal5=44name6=
    asdasdfinal6=25name7=Gekheid
    final7=20name8=Nick
    final8=16name9=
    pietjefinal9=11name10=Truusfinal10=2The data has been written to the table!?>


    So they are not in a tabel or something... Is this something I have to do in PHP or Flash?
    And how? Can somebody help me with that

    Tnx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center