Chapter . Introduction

This is the second edition of Macromedia Flash ActionScript for Fun & Games. Here you will find all the material covered in the first edition, plus updates and 12 new games.

This book looks at ActionScript by presenting many complete programs. Each program contains a lot of ActionScript code that you can look at, learn from, and alter. Better still, these programs are toys, gadgets, and games.

This second edition is for Flash MX, also known as Flash 6. Although many of the book’s first edition games will still work with Flash 5, you should be using Flash MX if you plan to use this book to learn ActionScript.

Although Flash 5 was the first version of Flash deep enough to allow us to make good Web-based games, Flash MX is even better. Most notably, Flash MX is much faster than its predecessors. This means that our games will run more smoothly on a larger number of user computers. In addition, we can now attempt some more complex games that are only possible with this better performance.

The first edition of this book was so well received that I didn’t want to mess with it too much. So instead of changing the book, I simply added to it. Chapters 5 through 16 each have a new game, matching the theme of the rest of the chapter and usually building on what was taught in the earlier games of the chapter.

I’ve also updated several games to take advantage of some of Flash MX’s new capabilities. For instance, the drawing program in Chapter 7, “Construction Toys,” now uses Flash MX drawing commands instead of duplicating movie clips. In other cases, where performance in an older game would not have changed, I’ve left the ActionScript with code that works in both Flash 5 and MX.

What Is in This Book?

Although Flash has just recently come of age as a programming environment, it long ago established itself as an entertainment medium. Flash is used for everything from Web site window dressing to long-playing animated features.

With ActionScript, there is another side to Flash that still deals with entertainment: games. The contents of this book deal primarily with teaching you how to make games with Flash.

I start off by reviewing some Flash basics in Chapter 1, “Flash Elements Used to Make Games and Toys,” by focusing on how different elements of Flash can be used to make interactive applications. Chapter 2, “An Introduction to ActionScript,” will come in handy for someone who has used Flash a lot but hasn’t done much programming before. It also will help people who have programmed in other languages, but never before in Flash.

Chapter 3, “ActionScript Elements Used to Make Games and Toys,” looks at different ActionScript elements and techniques and shows you how they can be used to create games and other things. This chapter gives you the background you need for the rest of the book. In Chapter 4, “The Game-Creation Process,” you learn about game planning and programming.

The rest of the book, except for the last chapter, contains many example programs with all the source code. Chapter 5, “ActionScript Design Effects,” Chapter 6, “Toys and Gadgets,” and Chapter 7, “Construction Toys,” describe toys and gadgets that are fun, but not necessarily games. Then, starting with Chapter 8, “Hunt and Click Games,” all the way through to Chapter 16, “Arcade Games,” the rest are all about games.

Each section in Chapters 5 to 16 starts by describing the game to be built. Then it describes my approach to building the game. Next, the elements needed to make the game are reviewed. Finally, the code for each game is revealed, with descriptions about what each part of the code does. Each section ends with some comments about how the game can be taken even further.

The book ends with Chapter 17, “Advanced Techniques,” in which you learn some special techniques, such as high score boards and preloading screens. Finally, don’t miss the comprehensive list of Web resources in Appendix A, “Internet Resources for the Flash Developer.”

The bottom line is that this book contains lots of ActionScript code! There are far more lines of code in this book than in any other I’ve ever seen on Flash. There are about 37 games here, with all the source code printed in the book and available to you on the CD-ROM.

Who Is This Book For?

This is a hands-on guide to learning ActionScript; it’s not a book for dummies or idiots. What this means is that I don’t hold the reader’s hand through every step of every project in every chapter. If a technique is covered in an earlier chapter, I might not explain it all over again. Instead, I take that project deeper and explain a new technique so that you can continue to learn new things.

This book requires you to learn and think. If you don’t understand something the first time, read over the text again, try the example on the CD-ROM, and play with the technique in Flash before moving on. You’ll benefit in the long run with a deeper understanding of how ActionScript works and how to use it in projects beyond the scope of this book.

This book can be used by a variety of people. If this book has caught your eye in a bookstore, an online bookseller, or you are looking at a friend’s copy, then chances are you fall into one of these groups.

Animators

As an animator, you already use Flash to create linear animation. Perhaps you know how to make a button or two as well. This book takes you beyond that into the wonders of ActionScripting. You’ll learn how to put your animated characters and scenes inside toys and games.

Illustrators

If you are a graphic designer, chances are that you have worked in Flash or another vector-drawing program. By using the tutorials that come with Flash MX, you can learn how to draw in Flash. Then you can use this book to make your drawings interact with the users in toys and games.

Programmers

Perhaps you are a programmer who has worked in another language such as Java, C++, or Lingo. This book teaches you how to use your programming skills in Flash. You can get a good overview of ActionScript in Chapters 1 to 3, or just dive right into source code starting with Chapter 5.

Flash 3 and Flash 4 Programmers

This book is also good for Flash 3 or Flash 4 programmers looking for a guide to help them take the leap to Flash MX. The difference between programming Flash MX or Flash 5 and earlier versions is quite large. The environment and commands are almost completely different. To really use the power of Flash MX, you’ll have to forget about many techniques used in earlier versions and start learning again from scratch.

Readers of the First Edition of This Book

If you have used the Flash 5 version of this book, you are probably wondering whether this book is worth buying. I thought a lot about readers of the original book while adding the new material. I wanted to be sure there would be plenty of new stuff to learn. Each chapter, from 6 through 16, includes a new game. In most cases, this new game builds on the games from the first edition and presents an even more complex example. Think of this book as “Volume II,” but with all the material from the first book so you don’t have to keep two books on your desk.

Web Home Page Owners

Maybe you are not a computer professional, but just someone who has a home page and some spare time to improve your skills. Flash MX is a fairly inexpensive development program for you to use to improve your site. With this book, you can immediately grab a game that you like, maybe alter the graphics a bit, and post your own game. Don’t expect miracles without putting in the time to learn Flash basics and the material in Chapters 1 through 4, but a smart, hands-on learner should be able to get going quickly.

Professional Web Site Developers

If you are a professional Web site developer, you might be expected to have many skills under your belt. You’ll need to know HTML, style sheets, JavaScript, Perl, and several programs such as PhotoShop or Fireworks, Dreamweaver, and so on. Flash is also quickly gaining status as one of the tools that every Web site developer should know.

But knowing the basics probably isn’t enough. You’ll eventually need to create something. Although other books teach you the basics and leave it up to you to figure out how to put the pieces together to create full programs, this book shows you how to create these programs. You can learn from this to create your own programs from scratch, or use one of the games here as a jump-start to quickly create your own version.

Students

Flash is being taught in many colleges and universities today. This trend will continue as Flash continues to gain popularity. This book could be used as a hands-on text for students wanting to learn ActionScript. Some classes might only teach Flash basics, and you can use this book to place you ahead of everyone else. Other classes might be more advanced and use this book as a text for hands-on learning.

What Should You Already Know?

This book is obviously not meant to be a general reference book for Flash MX. Instead, it is a hands-on learning resource for Flash MX ActionScript. The book already assumes that you are somewhat familiar with Flash’s interface and operation.

This does not mean that you need to be an expert graphic artist. I’m not. Many people associate Flash only with graphic talent. This was true when graphics were all that early versions of Flash could do, but now it is a programming environment as well. This book can be used by expert illustrators and programmers alike.

What you should know is how to use the basics of Flash. You should be familiar with all the ideas in the tutorials that come with Flash MX. You should know how to work with the main timeline to add frames and label them. You should know how to create movie clips, buttons, and graphics. They don’t have to look great; you just need to know the procedure for creating them in Flash.

On the other hand, some people will be able to use this book even if they have never used Flash before. If you are a patient, hands-on learner, willing to spend the time to immerse yourself into a new subject until you learn it, you can use this book to jump right past beginner Flash techniques and into expert ActionScript programming.

What Can You Do with This Book?

So now that you’ve determined that you are one of the types of people who can use this book, the next question is, “What can this book do for you?”

Learn ActionScript

There are several ways to use this book—the first is to use it to learn ActionScript. This book goes way beyond a simple beginner’s guide, teaching you how to use ActionScript for complex things.

You’ll learn about a wide variety of commands, functions, and techniques used in games and other applications. You’ll not only learn what these things do, but see them inside real programs so that you can better understand how they work.

Learn How to Create Games in Flash

All the programs in this book can be considered some type of game or something that can be used as part of a game. Even if you already know ActionScript, this book can teach you how to use that knowledge to create games. In Chapter 4, I will go into detail about how games are made. The rest of the book is packed with examples.

Stealing These Games

Of course, you can buy this book, take the source code, and make your own games. You can take the source code as it is and post the games on your Web site; however, you will probably want to give them your own graphic style first.

Keep in mind, however, that the book and source code are written for those interested in learning about ActionScript. Don’t expect to be able to jump right to Chapter 16 and start tinkering with code. Although some people might be able to do this, others will have difficulty without the information in Chapters 1 to 15.

Chapter 4 goes into some detail about how to take the games in this book and customize them to make your own. Then, a section in each chapter after that gives suggestions on what you might do to the games to make them your own.

The CD-ROM

A book like this would not be very useful if you had to type in every source code listing yourself. The way Flash movies are put together makes this even harder, because so many different elements, such as movie clips, buttons, and graphics, need to be placed in just the right spot.

To make the process of understanding the programs easier, you should always refer to the source code files on the CD-ROM.

While you go through each project, always remember to open the example movie on the CD-ROM to see the real program in action. Then use this source file to make modifications or test out new code.

You’ll see a line like this to tell you which file to use:

The CD-ROMExample file: Example.fla

Although typing in the source code and trying to re-create the examples is probably a good exercise, even the most precise developer will find it hard to re-create complete, complex programs from the pages in a book.

Conventions

There are several conventions in this book to help you understand what you are reading. Any words that you see in italics are real commands, functions, or other pieces of syntax that are part of ActionScript. You can look up any of these in the Flash MX documentation. For instance, gotoAndPlay(), stop(), and _x.

On the other hand, if you see something in quotes, such as “myVariable,” then it is a user-defined piece of syntax. These are usually variable names or user-defined function names.

While you are looking through the code, you will often see two slashes together like this: “//.” This is Flash’s way of saying that the text after the slashes is a comment. This often happens at the beginning of lines, so that the entire line is a comment. If you typed in the code without any of my comments at all, it would still work in the same way. The comments are just my way of letting you know what is happening in the code. You should adopt the practice of commenting your code as well. Commenting your code can help you or your co-workers alter your games in the future.

Updates and Communication

While writing this book, I took a lot of care to be sure no errors or omissions exist. I write as carefully as I can, and several editors look over the text before publication. However, there is only a limited about of time to produce a book like this. If I took all the time I needed to make sure the book was perfect, it would be obsolete by the time it was published.

It is inevitable that the readers will discover minor issues with some of the code. It’s also probable that future versions or bug fixes of Flash will produce some changes in ActionScript that will require some changes in the code here. When this happens, I will post updates and corrections on a special page located at my Web site: http://garyrosenzweig.com/books/book9support.html. You can also go to this page to read about how to contact me or the publisher.

My site will contain information about the book for those who have not bought it yet, updates, links to resources, and a way for you to send feedback to me about the book.

Have Fun

I hope you can learn something from this book that helps your career, your company, or your Web site. But most of all, I hope you enjoy it.

Although many people are buying this book for professional or educational reasons, remember that this is a book about games. Games are a form of entertainment. I hope you find that making games is even more fun than playing them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.114.142