02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> <strong>Games</strong><br />

10 //Connect <strong>to</strong> the database<br />

11 var conn = Server.CreateObject("ADODB.Connection");<br />

12 var connStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA SOURCE=" +<br />

13 Server.Mappath("register.mdb") + ";" + "Password=;";<br />

14 conn.Open(connStr);<br />

15<br />

16 var rs = Server.CreateObject("ADODB.Recordset");<br />

17 var sqlStr = "SELECT * FROM Users WHERE name=\’" + name +<br />

18 "\’ AND pw=\’" + pw + "\’";<br />

19<br />

20 rs.Open( sqlStr, conn);<br />

21<br />

22 var str;<br />

23<br />

24 if (!rs.EOF){<br />

25 str = ("loggedIn=true&message=Welcome back " + name);<br />

26 Session("loggedIn") = true;<br />

27 Session("playerID") = String(name);<br />

28 Response.Cookies("name") = name;<br />

29 Response.Cookies("name").Expires = getExpireString();<br />

30 }else{<br />

31 str = "loggedIn=false&message=Can’t find you in our database";<br />

32 Session("loggedIn") = false;<br />

33 Session("playerID") = "";<br />

34 }<br />

35<br />

36 Response.Write(str);<br />

37<br />

38 rs.Close();<br />

39 conn.Close();<br />

Listing 21.6<br />

Registering via ASP<br />

First we parse all the data sent <strong>to</strong> the page and s<strong>to</strong>re it in several variables. Then we connect <strong>to</strong> the<br />

database and build an SQL string. This time the string is an INSERT string that takes the form<br />

INSERT INTO table (field1, ...) VALUES(val1, ...)<br />

This is executed on the current connection. To make a full registration application we should<br />

really check for the existence of a user with the same name, because the ‘name’ field is required<br />

<strong>to</strong> be unique. We can find out whether a user with the same name exists simply by creating<br />

a recordset from the Users table based on the name value being the same; if this recordset has<br />

any entries then the name has already been used and so we can write back a message <strong>to</strong> indicate<br />

this and the <strong>Flash</strong> application can require the user <strong>to</strong> choose a different name. The function<br />

338

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!