A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11358 Flash Movies | 4 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Sean
» Title: Customizable Flash Drop down menu
» Description: The native source files for building a customizable menu roll down.
» More by Sean


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5709 Flash Sites | 4 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Sandy 3D Engine for Flash
» Description: Sandy is a Flash 3D engine, available in 3 versions: AS2, AS3 and haXe


Random Links | Add your own Flash Related Links
Flash Tutorials 1302 Tutorials 7 New Tutorials Added!
What's New | Top100

» MySpace profile flash slideshow
» Display YouTube videos in self-customized Flash video player on website
» How to make cool 3D flash banners for your website?
» Make a Valentines Day Slideshow with Music
» How to remove red eyes from a photo?
» How to convert SWF to Animated GIF on Mac
» How to Make a Platform Game using AS 2 - Part 1
» How to make a flash Greeting e-card
» How to extract Youtube video to MP3 audio for Mac
» Unknown Tag: Title10
Random Tutorial | Add Site

Web Manager
University of Redlnads
US-CA-Redlands

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Games

Categories PHP/MySQL Highscore tutorial
Author: Jeroen den Haan | Website: http://www.ssj-games.com |

 
Page 1
1

Highscore Tutorial

One of the little things for a nice Flash game is a tutorial. It's making people to go back to your game and play it again to win from the competition. It's a way of competition and interactivity between the players to do their best and win as much points as they can.

Things you need
1. A webserver enabled with PHP and MySQL. Almost all unix/linux webservers have these two, because they are free for everyone. If you don't know if you have PHP4/MySQL enabled, contact your Hosting Company.
2. Notepad. Or a similar text editing program.
3. A FTP program to upload your files. CuteFTP or WS_FTP are two examples.
4. The files that come with this tutorial. (highscore_tut.zip)
5. Your nice Flash game. Duh..

The first few things.
Open '_data.php'. This is rather important. You need to change a few things here. You need to input the right usernames/passwords/game name/other things. You will have to change at least numbers 1 to 6. The numbers 1-3 are the few things you need to enter to make contact with the MySQL database. You've got those from your Hosting Company. If not, ask them. 7-14 are optional, they don't need to be changed to get it all working. All things are rather straigtforward.

Upload _data.php/get_score.php/install.php/new_score.php to your website's root directory. Run the install.php script. When it sais 'Done..', you can delete the install.php file from your website. Done.

Why PHP/MySQL? PHP, PHP Hypertext Processing is a free server-based scripting language that is free and provided by a lot webserver/hosting companies. Other than that, it's a very fast language, faster then ASP(from Micro$oft). MySQL is the perfect database partner for PHP. Together they can be fast and above all secure.

Adding new people to the scores.
Ok, now we are going to start with the Flash part. When you want to send your highscores from Flash to the MySQL server, you'll need this Actionscript:

_root.add_pass = "{same as $pass in _data.php}";
 _root.name = _root.variableYouUsedInTheGameForThePlayersName;
 _root.score = _root.variableYouUsedInTheGameForThePlayersScore;
 getURL("new_score.php", "", "POST");

That's it! The PHP script itself makes sure the player gets added to the database and all other things you don't need to worry about.

Showing the Highscore in Flash.
This is rather easy. Make 10 variable text boxes in a column.(Or the number you used in the _data.php file as $st_size.) These dynamical text boxed are named 'name1' to 'name10'. (Or different, again corresponding to the Standard Size inputted in _data.php.) Then make 10(Or blab, bla, you know..) dynamical variable text fields next to each corresponding text box called 'score1' to 'score10'.

I am not taking this anyfurther, but you can understand that you can make the looks of your Highscore list somewhat nicer than standard.. ;)

Now use the following Actionscript code to load the variables from the database back into Flash:

 	   loadVariablesNum("get_score.php?flash=1", 0);
Now the variables get loaded into the _root. But if you have your Highscore list in a movieclip, you should use this code:
  	   loadVariables("get_score.php?flash=1", "_root.scoretableOrAnyOtherMCname");

The location of the Flash game's SWF file and the location of the Highscore scipts must be at the same domain. (And in these Actionscript code, it must be in the same folder as well.) This is a standard security feature from Macromedia Flash. It can't be changed, live with it.

Including the Highscore list on your webpage.
It is possible to include a HTML highscore list on your webpage. This is realy nice for your site's visitors.

Your page where you want it to show must be a PHP page as well. We take 'index.php' as an example. The $dis_file variable in _data.php must be the same as this page. Now, where ever you want the Highscore table to appear on your page, you include this:

<?php
 include("http://www.ssj-games.com/get_score.php");
 ?>

You can change some graphics from the HTML table in _data.php if you want, but look out to only use ' in the code instead of ". That is VERY important.

Ending
Well, that's about it. You can use this to make your own nice Highscore for every game you want.

If you have any comments, questions or suggestions, you can email me at jeroendenhaan@yahoo.com, or visit my site at http://www.ssj-games.com (comes online very soon..^^)

1

» Level Intermediate

Added: : 2002-04-16
Rating: 5.93 Votes: 86
Hits: 651
» Author
This is 'jeroen84' on the Flashkit boards..
» Download
Download the files used in this tutorial.
Download (6 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers