ASP
  Home arrow ASP arrow Page 2 - Central Scoreboard with Flash and ASP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Central Scoreboard with Flash and ASP
By: Chris Worfolk
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 79
    2004-03-22

    Table of Contents:
  • Central Scoreboard with Flash and ASP
  • The database
  • Adding player’s scores
  • The Flash file

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

    More ASP Articles
    More By Chris Worfolk


       · Thank you for the scoreboard, once I click my button in flash to go to asp, it gives...
     

    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...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT