Home arrow ASP arrow Page 2 - Central Scoreboard with Flash and ASP
ASP

Central Scoreboard with Flash and ASP


Adding a few flash games to your site is always a great way to get visitors to stay on your site a bit longer and even keep them coming back. It’s well known that one of the best ways to keep visitors coming back is interactivity. So why not let your visitors battle it out between each other?

Author Info:
By: Chris Worfolk
Rating: 4 stars4 stars4 stars4 stars4 stars / 117
March 22, 2004
TABLE OF CONTENTS:
  1. · Central Scoreboard with Flash and ASP
  2. · The database
  3. · Adding player’s scores
  4. · The Flash file

print this article
SEARCH DEVARTICLES

Central Scoreboard with Flash and ASP - The database
(Page 2 of 4 )

First thing to do is create a blank database; I called mine database.mdb to keep things simple. In the database you need to create a table to hold the scores, surprising enough I called mine: scores.

The structure should be:

Player (text field, default length)
Score (number field)

Let’s also add some default players so that there are already results on the scoreboard when visitors start playing. I have done it 3 letter arcade style throughout the article:

  • CJK – 10000
  • SAM – 20000
  • XER – 30000

Once you have entered the values you can close the database, we won’t need to open it again.

The scoreboard file
Now open up your text editor and create a file called scoreboard.asp. This will extract the top 3 results from the database along with their scores so that the flash file can read the top scoring players and compile them into a scoreboard.

Define a connection to the database and open up a recordset:

<%
conn = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=” + Server.MapPath(“database.mdb”)
set rs=Server.CreateObject("ADODB.recordset")
rs.Source = "SELECT * FROM scores ORDER BY score DESC"
rs.ActiveConnection = conn
rs.Open()

Now we need to write out the variables of the top 3 players:

Number=1
Do until number = 4
   response.write("player" & number & "=" & (rs.Fields.Item("player").value)) & vbCrLf
   response.write("score" & number & "=" & (rs.Fields.Item("score").value)) & vbCrLf
number = number + 1
rs.MoveNext
loop

Then finally close the recordset

rs.Close()
Set rs = Nothing

You can then upload these files and open them in your browser (or skip past the uploading if you’re working on your local machine). It should produce:

player1=XER score1=30000 player2=SAM score2=20000 player3=CJK score3=10000

Adding player’s scores
Next we need a file that will add player’s scores when they are sent. We also need a system to stop users adding scores to the database without actually playing the game. Bring up a new file in your text editor and save it as addscore.asp. This file will be sent variables from the flash movie:

Player – this will be the player’s name
Score – the player’s score
Passcode – this is a variable that makes sure the user is not just accessing the page using their browse

In this file we open up the connection as normal but change the SQL:

<%
If Request.Form("passcode") = "XHjf5" Then

Dim playername
playername = "XXX"
If Request.Form("player") <> "" Then
 playername = Request.Form("player")
End If
playername = (Left(playername, 3))

Dim conn
conn = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + Server.MapPath("database.mdb")

set rs=Server.CreateObject("ADODB.recordset")
rs.Source = "INSERT INTO scores (player, score) VALUES ('" + Request.Form("player") + "', " + Request.Form("score") + ")"
rs.ActiveConnection = conn
rs.Open()

rs.Close()
Set rs = Nothing

End If

Response.Write(“Score Recorded. Close Window”)
%>


conn "Driver={Microsoft Access Driver (*.mdb)}; DBQ=” + Server.MapPath(“database.mdb”)
set rs=Server.CreateObject("
ADODB.recordset")
rs.Source = "
SELECT FROM scores ORDER BY score DESC"
rs.ActiveConnection = conn
rs.Open()

Now we need to write out the variables of the top 3 players:


Number=1
Do until number 
4
   response
.write("player" number "=" & (rs.Fields.Item("player").value)) & vbCrLf
   response
.write("score" number "=" & (rs.Fields.Item("score").value)) & vbCrLf
number 
number 1
rs
.MoveNext
loop

Then finally close the recordset.


rs.Close()
Set rs 
Nothing

You can then upload these files and open them in your browser (or skip past the uploading if you’re working on your local machine). It should produce:


player1=XER score1=30000 player2=SAM score2=20000 player3=CJK score3=10000


blog comments powered by Disqus
ASP ARTICLES

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials