PDA

View Full Version : [AS3] Highscore list using Flash and PHP


Geert81
04-07-2010, 12:07 PM
Hi,

I want to make a highscorelist using AS3 and PHP(MySQL).
I cant find a good tutorial on internet how to make something like that but I got this so far:
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 data I have given in:

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

scorpion9
04-07-2010, 12:20 PM
//lets suppose that u have a button movieclip on the stage with the name button_mc
//also, u have a textfield with the name input_tf
//then u need the following code

button_mc.addEventListener(MouseEvent.CLICK,handle Click);
function handleClick(event:MouseEvent):void
{
if(input_tf.text != "")/or check the length of the text != 0
{
//and then call the function that handles the score saving
SaveScore();
{
}

Geert81
04-08-2010, 06:28 AM
Hi,

Tnx for the reply I got everything working now!

Here is my AS3 code:

import fl.controls.TextInput;
import fl.controls.TextArea;
var variables:URLVariables = new URLVariables();

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();
///////////////////////////////////////////////
var punten:Number = 0;
score_btn.addEventListener(MouseEvent.CLICK, onButtonclicked);



function onButtonclicked(e:MouseEvent):void {
punten ++;
score_txt.text = String (punten);
}

score_txt.text = String (punten);
////////////////////////////////////////////
submitBtn.addEventListener(MouseEvent.CLICK,submit F); // where submitBtn is your button

function submitF(e:Event){
variables.name=nameTF.text; // where nameTF is your input texfield
variables.final = score_txt.text; // where score is the variable you use to tally user score
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);

}

The only problem now is that it is shown like this:

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

Is there someone that can tell me how I can put this in a nice tabel?
Tnx