Macromedia Flash 8 Bible Free Open Book

Macromedia Flash 8 Bible

Previous Page
Next Page

Added Feature: Storing User and Game Information

Being able to save information opens exciting dimensions to game development. For example, users particularly enjoy playing a multilevel game if they know the next time they visit the site, they can pick up where they left off because the computer remembers which level they last completed and their current score.

For our Hangman game, the following section demonstrates a very simple application of saving data onto the user's local hard drive and recalling it when the player returns to the game at a later time.

Flash Player 6 introduced a new feature, the SharedObject class, which enables you to save data locally, similar to a Web browser cookie. The next time the user runs the game, it displays the saved information. The information can be saved in two ways: when the movie ends or as soon as the information is entered. For our game, the information is saved right away, in the init() function of the GameModel class. The SharedObject.getLocal() method creates a new object named so.

so = SharedObject.getLocal("hangMan");

To store data in a SharedObject instance, you access the data property of the instance, followed by a variable name. For example, to store a variable named firstName in a SharedObject instance named so, you could use the following code:

so.data.firstName = "Damian";

For the purposes of this game, we check that the data was saved for the username and the win and loss scores. If any of this information is unavailable, the GameModel class dispatches the event "init" when the gameState property is set to "init" in the checkLocalData() function of the GameModel class.

When the game is played for the very first time, the player enters his/her name. Every time after that, the name and score are remembered and displayed.

After the user enters his/her name and clicks the orange button (mcBtn instance of the GameView class) on the screen, the data is saved by calling the saveName() function of the GameModel class:

Public function saveName(sName:String):Void {
  so.data.user = name;
  so.flush();
}

Note 

The flush() method of the SharedObject class forces the data to be written to the local data file.

The saveScore() function of the GameModel class is called from within the game at the end of each round and stores the win and loss scores.

private function saveScore():Void {
   so.data.winScore = win;
   so.data.lossScore = loss;
   so.flush();
}

And that ends our deconstruction of the Hangman game! We encourage you to modify the elements in the View Assets folder to suit your own particular tastes for the game's look and feel.

Web Resource 

We'd like to know what you think about this chapter. Visit www.flashsupport.com/feedback to send us your comments.


Previous Page
Next Page
Index: [A][B][C][D][E][F][G][H][I][J][K][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y][Z]


     Main Menu
Table of Contents
Back Cover
Macromedia Flash 8 Bible
Foreword
Preface
Part I: An Introduction to Flash Web Production
Part II: Mastering the Flash Environment
Part III: Creating Animation and Effects
Part IV: Integrating Media Files with Flash
Part V: Adding Basic Interactivity to Flash Movies
Part VI: Distributing Flash Movies
Part VII: Approaching ActionScript
Part VIII: Applying ActionScript
Chapter 28: Sharing and Loading Assets
Chapter 29: Sending Data In and Out of Flash
Chapter 30: Applying HTML and Text Field Formatting
Chapter 31: Creating a Game in Flash
The Game Plan: Four Phases of Game Design
Building the Project
Scripting the Game
Initializing the Game
Building the Interface
Starting the Game
The User Input
Interpreting the User Input
Checking the Status of the Game
Added Feature: Storing User and Game Information
Summary
Chapter 32: Managing and Troubleshooting Flash Movies
Part IX: Integrating Components and Data-Binding
Part X: Expanding Flash
Part XI: Appendixes
Index
List of Figures
List of Tables
List of Listings
List of Sidebars


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele