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

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

66<br />

67 conn.Close();<br />

68<br />

69 %><br />

Listing 21.11<br />

ASP pages are an easy way <strong>to</strong> link between <strong>Flash</strong> and a database. Because you can write ASP pages<br />

in JavaScript and that is the syntax used in <strong>ActionScript</strong>, you are already well on your way <strong>to</strong><br />

becoming a JavaScript expert.<br />

Creating administrative pages<br />

The administra<strong>to</strong>r for your site will want <strong>to</strong> be able <strong>to</strong> read and manipulate the database. SQL<br />

Server is very good for maintaining a remote database, Access is more limited. Sometimes the best<br />

way <strong>to</strong> create an easy-<strong>to</strong>-maintain site is <strong>to</strong> create admin pages. Such pages are designed <strong>to</strong> allow<br />

the administra<strong>to</strong>r <strong>to</strong> check such features as traffic and users. We have found that cunning players<br />

often find ways <strong>to</strong> fake a high score, sometimes by sending a score directly <strong>to</strong> the database using<br />

the ASP pages that <strong>Flash</strong> uses. This happens particularly on prize-winning games. To avoid this<br />

happening we have taken <strong>to</strong> using encryption techniques for most data that we send by ASP. The<br />

Webmaster can often spot someone cheating simply by checking his or her records in a database.<br />

<strong>Flash</strong> is a good <strong>to</strong>ol for creating user-friendly front ends <strong>to</strong> allow a Webmaster <strong>to</strong> check out the<br />

database. The ‘admin.fla’ project shows how you can tie a <strong>Flash</strong> application <strong>to</strong> a database. The<br />

‘Grid’ component has three parameters, rowCount, colCount and colNames – an array of strings.<br />

These can be set directly at design time or you could create ASP pages <strong>to</strong> get the <strong>to</strong>tal number<br />

of columns and the names from a table in the database. Having accessed this information you can<br />

use it <strong>to</strong> initialize the grid <strong>to</strong> the appropriate column headers and the appropriate data in the cells.<br />

You could create a but<strong>to</strong>n that allows users <strong>to</strong> delete or update records. You could even let users<br />

write their own SQL strings and then use these <strong>to</strong> update the database. By linking <strong>Flash</strong> and ASP<br />

pages in this way you can provide all the functionality a Webmaster could ever need.<br />

Summary<br />

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> is a great <strong>to</strong>ol for linking <strong>to</strong> server-side scripts. Because we can get data out of <strong>Flash</strong><br />

using a query string or the POST method, we can easily send this <strong>to</strong> a server-side script. On the<br />

server we can use the data <strong>to</strong> manipulate a database then send this information back <strong>to</strong> <strong>Flash</strong> using<br />

a MIME-encoded string. We can send as many variables in this way as are needed for a particular<br />

task. There are many books on ASP, a lot of which use VBScript as the scripting language, so you<br />

may find them unfamiliar at first but a lot of the detail will be the same if you use JavaScript as<br />

your scripting language.<br />

In this chapter we explored more fully some of the features of ASP and SQL. If you are<br />

manipulating databases then it well worth learning more about SQL. The language offers you a<br />

great many <strong>to</strong>ols for selecting records from databases and linking <strong>to</strong>gether tables. Check out the<br />

bibliography for some interesting SQL books.<br />

346

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

Saved successfully!

Ooh no, something went wrong!