00:00
00:00
Newgrounds Background Image Theme

MagDeWarrior just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Scoreboard

8,955 Views | 13 Replies
New Topic Respond to this Topic

AS: Scoreboard 2005-08-26 17:24:12


AS: Main

This is a basic tutoarial using the following:

PHP
MySQL
Flash ActionScript

This is mainly an ActionScript tutorial, the PHP and MySQL part is minimized to "copy and paste"

Stages

1)Getting a server
2)Setting the files and writing them
3)Setting the actionscript

WARNING: This scoreboard tutorial will produce a working but hackable scoreboard, you'll need to protect it better if you want it practically used , I might write a follow up tutorial or I might get Denvish to :P

Getting a server
The first thing you need to do is get a server that supports both PHP and MySQL there are plenty of free servers providing these services and you shouldn't care about ADs since you aren't using the pages themselves (you're loading them directly to flash), if you want to get something professional you should get a payed server, 3qhost are fair and trustworthy (I used them twice) and apthosting are pretty good too.

Setting the script

This script will include 1 php file and 1 sql table, let's start with the tricky sql part, your host should have some form of SQL access (preferable CPanel with PhpMyAdmin which is best to use). connect to your SQL (as provided) and create a new scores table:

CREATE TABLE `scores` ( `name` VARCHAR( 30 ) NOT NULL , `score` INT NOT NULL , `id` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) );

basically I created a table with a place for names and a place for scores, names are limited to 30 chars but you can use more if you'd like

now make sure you have the sql connection script ready, it's

mysql_connect(<server>,<username><userpass
>);
select_db(<database name>);

create a new php file, name it highscores.php or something similar, and put the following script in it, costumizable parts have <>'s


<?
$action=$_POST['action'];
echo "returned=1";
echo $_POST['lolk'];
function spitScores($n){
$result=mysql_query("SELECT * FROM `scores` WHERE 1 ORDER BY `score` DESC");
for($i=0;$i<10;$i++){
$row = mysql_fetch_array($result, MYSQL_BOTH);
echo "&row" . $i . "=" . $row['name'] . "&score" . $i . "=" . $row['score'];
}
}
function insertScore($name,$value){
if($value<100000){
mysql_query("INSERT INTO `scores` ( `name` , `score` , `id` ) VALUES ('$name', '$value', '');");
}
}
function clearDB(){
mysql_query("DELETE * FROM 'scores'");
}
if($action!=null){

mysql_connect(<server>,<username><userpass
>);
mysql_select_db(<database name>);

}else{
die ("I cannot find the action");
}
if($action=="view"){
spitScores(10);
}else if($action=="insert"){
$name=$_POST['name'];
$score=$_POST['score'];
$domain=$_POST['domain'];
//if(($domain=="http://www.gamesofgondor.c
om") || ($domain=="http://uploads.ungrounded.net")
){
insertScore($name,$score);
// }else{
// echo "Stop trying to cheat the system";
// }
}else if($action=="clear"){
$pass=$_POST['password'];
if($pass=="<myclearpasshere(give it to noone)>"){
clearDB();
}

}else{
"Please don't hack this, if scoring high REALLY means that much to you just email us and we'll give you a highscore, just don't be such a godamn lamer and ruin someone's hard work" ;
}
?>

once you have this code you're pretty much set, all you have to do is fetch the scores from flash...

you'll notice you have a domain check with a remark bound before it at a point, you can unremark it and alter it as you need

The Actionscript

You have 3 actions in this scoreboard script, view insert and clear, you only need to mess with view and insert, for example to insert a score you can do

action="insert";
name="Inglor"
score=2000;
loadVariablesNum("www.site.suffix/path/hig
hscores.php",1,"POST");

to view the scores you need to do
action="view";
loadVariablesNum("www.site.suffix/path/hig
hscores.php",1,"POST");

Again, this script is not secure, only use it for education and learning how highscores work, the view action loads the variables into _level1, toy with it to check the format, it loads 10 scores (configurable)

enjoy!

Response to AS: Scoreboard 2005-08-26 17:27:05


Cool. I've not used PHP much, but I wrote a tut for a Flash/ASP scoreboard (with sample files) here. I will come back and offer some tips for preventing hacking at a later date.


- - Flash - Music - Images - -

BBS Signature

Response to AS: Scoreboard 2005-08-26 17:27:15


google it, it's free

Response to AS: Scoreboard 2005-08-26 17:28:33


Great work! Too bad so many people are desperate for highscores though >:-(


BBS Signature

Response to AS: Scoreboard 2005-08-26 17:30:22


Oh, and also check out AS: Load External Data/Cross-Domain for information about using cross-domain scoreboards. If you're planning on using a scoreboard in a Flash submitted to NG, it WON'T WORK unless you sort out the crossdomain.xml on the database domain.


- - Flash - Music - Images - -

BBS Signature

Response to AS: Scoreboard 2005-08-26 17:33:48


At 8/26/05 05:27 PM, Denvish wrote: Cool. I've not used PHP much, but I wrote a tut for a Flash/ASP scoreboard

that's cute but ASP is dead :P

Response to AS: Scoreboard 2005-08-26 17:38:02


too bad i cant put php on freewebs. cuz i reeeeeaaly want to learn xml server crap with flash.

Response to AS: Scoreboard 2006-03-31 12:57:48


At 8/26/05 05:38 PM, ImpotentBoy2 wrote: too bad i cant put php on freewebs. cuz i reeeeeaaly want to learn xml server crap with flash.

go on [=Arroways!=] ^^

Response to AS: Scoreboard 2006-04-30 10:36:41


Doesn’t work.

Database remains empty after i press the button with the code, even in its original form.

Response to AS: Scoreboard 2006-04-30 13:24:27


I used the php code from some other tutorial and used Inglor’s AS. It now submits the score but the username is: _level0.post or undefined. So how do I fix this?

I have tried many methods and this is the last one:

on (release){
action= "insert";
userName = _parent.post_game.player_name;
myScore = _root.total_score;
loadVariablesNum("addScore.php",1,"POST");
}

“player_name” is the instance name of the player name input. “post_game” is the MC where the input box and the “send score” button resides.

Any suggestions?

Response to AS: Scoreboard 2006-05-30 21:35:29


alright, lets say that i have 20 dynamic text boxes, 10 named "name0" through "name9" the other ten "score0" though "score9" how do i take the data from the php file, and make the scores and names display in their desired text boxes?

Response to AS: Scoreboard 2007-01-15 03:12:56


http://www.armorbot.com

you all get redeemed for free

Response to AS: Scoreboard 2007-01-15 07:38:45


At 1/15/07 03:12 AM, Inglor wrote: http://www.armorbot.com

you all get redeemed for free

Only those using MX+ :(

Response to AS: Scoreboard 2007-06-27 02:50:44


At 5/30/06 09:35 PM, EclipseNine wrote: alright, lets say that i have 20 dynamic text boxes, 10 named "name0" through "name9" the other ten "score0" though "score9" how do i take the data from the php file, and make the scores and names display in their desired text boxes?

Why the heck did this never get answered?