# Using ActionScript in Flash-P1

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:100

0
84
lượt xem
9

## Using ActionScript in Flash-P1

Mô tả tài liệu

Thương hiệu Thêm Life vào Web, Afterburner, dư chấn, Andromedia, Allaire, PowerPack Animation, Aria, đạt được, Authorware, Star Authorware, Backstage, Tiger Bright, Clustercats, Coldfusion, Đóng góp, Thiết kế In Motion, Giám đốc, Dream Mẫu, Dreamweaver, tiếng trống Năm 2000, EDJE, EJIPT, 3D Extreme, Fireworks, Flash, Flash Lite, Flex, Fontographer, tự do, phát điện, Homesite, JFusion, JRun, Kawa, biết trang web của bạn, đối tượng Kiến thức...

Chủ đề:

Bình luận(0)

Lưu

## Nội dung Text: Using ActionScript in Flash-P1

1. Using ActionScript in Flash
3. CONTENTS INTRODUCTION: Getting Started with ActionScript ....................... 7 Intended audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Using the documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Typographical conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Terms used in this document. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Additional resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 CHAPTER 1: What’s New in Flash MX 2004 ActionScript . . . . . . . . . . . . . . . . . . 11 Updating Flash XML files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 New and changed language elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 New security model and legacy SWF files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Porting existing scripts to Flash Player 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 ActionScript editor changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Debugging changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 New object-oriented programming model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 CHAPTER 2: ActionScript Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Differences between ActionScript and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . 24 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 About data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Assigning data types to elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 About variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Using operators to manipulate values in expressions . . . . . . . . . . . . . . . . . . . . . . . 49 Specifying an object’s path. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Using condition statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Using built-in functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Creating functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 CHAPTER 3: Using Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Working with FLA files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 General coding conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 ActionScript coding standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Using classes and ActionScript 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 3
6. APPENDIX A: Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 APPENDIX B: Deprecated Flash 4 operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 APPENDIX C: Keyboard Keys and Key Code Values . . . . . . . . . . . . . . . . . . . . . 313 Keys on the numeric keypad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Function keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Other keys. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 APPENDIX D: Writing Scripts for Earlier Versions of Flash Player . . . . . . . . . . . 319 About targeting older versions of Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 Using Flash MX 2004 to create content for Flash Player 4. . . . . . . . . . . . . . . . . . 320 APPENDIX E: Object-Oriented Programming with ActionScript 1 . . . . . . . . . . . 323 About ActionScript 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 6 Contents
7. INTRODUCTION Getting Started with ActionScript Macromedia Flash MX 2004 and Macromedia Flash MX Professional 2004 are the professional standard authoring tools for producing high-impact web experiences. ActionScript is the language you use to add interactivity to a Flash applications, whether your applications are simple animated movies or more complex rich Internet applications. You don’t have to use ActionScript to use Flash, but if you want to provide basic or complex user interactivity, work with objects other than those built into Flash (such as buttons and movie clips), or otherwise turn a SWF file into a more robust user experience, you’ll probably want to use ActionScript. Intended audience This manual assumes that you have already installed Flash MX 2004 or Flash MX Professional 2004 and know how to use it. You should know how to place objects on the Stage and manipulate them in the Flash authoring environment. If you have written programs before, ActionScript will seem familiar. But if you’re new to programming, ActionScript isn’t hard to learn. It’s easy to start with simple commands and build more complexity as you progress. System requirements ActionScript does not have any system requirements in addition to Flash MX 2004 or Flash MX Professional 2004. To use ActionScript 2.0, you must use Flash MX 2004. The documentation assumes that you are using the default publishing settings for your Flash files: Flash Player 7 and ActionScript 2.0. If you change either of these settings, explanations and code samples shown in the documentation may not work correctly. If you develop applications for earlier versions of Flash Player, see “Porting existing scripts to Flash Player 7” on page 13 or Appendix D, “Writing Scripts for Earlier Versions of Flash Player,” on page 319. Using the documentation This manual provides an overview of ActionScript syntax, information on how to use ActionScript when working with different types of objects, and details on the syntax and usage of every language element. The following list summarizes the contents of this manual. 7
8. • Chapter 1, “What’s New in Flash MX 2004 ActionScript,” on page 11 describes features that are new in ActionScript, changes to the compiler and debugger, and the new programming model for the ActionScript 2.0 language. • Chapter 2, “ActionScript Basics,” on page 23 describes the terminology and basic concepts used in the rest of the manual. • Chapter 3, “Using Best Practices,” on page 65 helps explain the best practices for using Flash and writing ActionScript. • Chapter 4, “Writing and Debugging Scripts,” on page 139 describes the ActionScript editor and debugger within Flash that makes it easier to write code. • Chapter 5, “Handling Events,” on page 167 discusses a few different ways to handle events: event handler methods, event listeners, and button and movie clip event handlers. • Chapter 6, “Creating Interaction with ActionScript,” on page 179 describes some simple ways in which you can create more interactive applications, including controlling when SWF files play, creating custom pointers, and creating sound controls. • Chapter 7, “Using the Built-In Classes,” on page 197 lists the built-in classes in ActionScript and provides a brief overview of how you use them to access powerful features in ActionScript. • Chapter 8, “Working with Movie Clips,” on page 205 describes movie clips and the ActionScript you can use to control them. • Chapter 9, “Working with Text,” on page 221 describes the different ways you can control text in Flash and include information on text formatting. • Chapter 10, “Creating Custom Classes with ActionScript 2.0,” on page 247 describes how to create custom classes and objects for manipulating data in your applications. • Chapter 11, “Working with External Data,” on page 275 describes how to process data from external sources using server- or client-side scripts in your applications. • Chapter 12, “Working with External Media,” on page 295 describes how to import external media files such as JPEG, MP3, and other SWF files in your Flash applications. • Appendix A, “Error Messages,” on page 305 contains a list of error messages that the Flash compiler can generate. • Appendix B, “Deprecated Flash 4 operators,” on page 311 lists all the ActionScript operators and their associativity. • Appendix C, “Keyboard Keys and Key Code Values,” on page 313 lists all the keys on a standard keyboard and the corresponding ASCII key code values that are used to identify the keys in ActionScript. • Appendix D, “Writing Scripts for Earlier Versions of Flash Player,” on page 319 provides guidelines to help you write scripts that are syntactically correct for the player version you are targeting. • Appendix E, “Object-Oriented Programming with ActionScript 1” provides information on using the ActionScript 1 object model to write scripts. This manual explains how to use the ActionScript language. For information on the language elements themselves, see ActionScript Language Reference Help. 8 Introduction: Getting Started with ActionScript