Programming_Actionscript_3.pdf
(
7298 KB
)
Pobierz
Programming ActionScript 3.0
PROGRAMMING ACTIONSCRIPT
™
3.0
© 2007 Adobe Systems Incorporated. All rights reserved.
Programming ActionScript™ 3.0
If this guide is distributed with software that includes an end-user agreement, this guide, as well as the software described in it, is
furnished under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any
such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means,
electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe Systems Incorporated. Please note
that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end-user
license agreement.
The content of this guide is furnished for informational use only, is subject to change without notice, and should not be
construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability
for any errors or inaccuracies that may appear in the informational content contained in this guide.
Please remember that existing artwork or images that you may want to include in your project may be protected under copyright
law. The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright
owner. Please be sure to obtain any permission required from the copyright owner.
Any references to company names in sample templates are for demonstration purposes only and are not intended to refer to any
actual organization.
Adobe, the Adobe logo, Flex, Flex Builder and Flash Player are either registered trademarks or trademarks of Adobe Systems
Incorporated in the United States and/or other countries.
ActiveX and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and other
countries. Macintosh is a trademark of Apple Inc., registered in the United States and other countries. All other trademarks are
the property of their respective owners.
Speech compression and decompression technology licensed from Nellymoser, Inc. (www.nellymoser.com).
Sorenson™ Spark™ video compression and decompression technology licensed from Sorenson Media, Inc.
Opera ® browser Copyright © 1995-2002 Opera Software ASA and its suppliers. All rights reserved.
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA
Notice to U.S. government end users. The software and documentation are “Commercial Items,” as that term is defined at 48
C.F.R. §2.101, consisting of “Commercial Computer Software” and “Commercial Computer Software Documentation,” as such
terms are used in 48 C.F.R. §12.212 or 48 C.F.R. §227.7202, as applicable. Consistent with 48 C.F.R. §12.212 or 48 C.F.R.
§§227.7202-1 through 227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software
Documentation are being licensed to U.S. Government end users (a) only as Commercial items and (b) with only those rights as
are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright
laws of the United States. Adobe Systems Incorporated, 345 Park Avenue, San Jose, CA 95110-2704, USA. For U.S.
Government End Users, Adobe agrees to comply with all applicable equal opportunity laws including, if appropriate, the
provisions of Executive Order 11246, as amended, Section 402 of the Vietnam Era Veterans Readjustment Assistance Act of
1974 (38 USC 4212), and Section 503 of the Rehabilitation Act of 1973, as amended, and the regulations at 41 CFR Parts 60-1
through 60-60, 60-250 ,and 60-741. The affirmative action clause and regulations contained in the preceding sentence shall be
incorporated by reference.
Contents
About this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Using this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Accessing ActionScript documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 15
ActionScript learning resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Chapter 1: Introduction to ActionScript 3.0 . . . . . . . . . . . . . . . . . . 19
About ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Advantages of ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
What’s new in ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Core language features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Flash Player API features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Compatibility with previous versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Chapter 2: Getting started with ActionScript . . . . . . . . . . . . . . . . .27
Programming fundamentals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
What computer programs do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
Variables and constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Working with objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Basic event handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Examining the event-handling process . . . . . . . . . . . . . . . . . . . . . 35
Event-handling examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Creating object instances. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Common program elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Example: Animation portfolio piece . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Building applications with ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . .47
Options for organizing your code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Choosing the right tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
The ActionScript development process . . . . . . . . . . . . . . . . . . . . . . . . 51
Creating your own classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Strategies for designing a class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Writing the code for a class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3
Suggestions for organizing your classes . . . . . . . . . . . . . . . . . . . . . . . 56
Example: Creating a basic application . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Running subsequent examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Chapter 3: ActionScript language and syntax . . . . . . . . . . . . . . . . 67
Language overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Objects and classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Packages and namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Type checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Dynamic classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Data type descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Type conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119
Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Basic function concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Function parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Functions as objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Function scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Chapter 4: Object-oriented programming in ActionScript . . . . . 137
Basics of object-oriented programming. . . . . . . . . . . . . . . . . . . . . . . . . 138
Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Class definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .141
Class property attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Enumerations with classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Embedded asset classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Advanced topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Example: GeometricShapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
4
Chapter 5: Working with dates and times. . . . . . . . . . . . . . . . . . . 191
Basics of dates and times. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Managing calendar dates and times . . . . . . . . . . . . . . . . . . . . . . . . . . . .193
Controlling time intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .196
Example: Simple analog clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199
Chapter 6: Working with strings . . . . . . . . . . . . . . . . . . . . . . . . . 203
Basics of strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Creating strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
The length property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Working with characters in strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Comparing strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Obtaining string representations of other objects . . . . . . . . . . . . . . . . 209
Concatenating strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Finding substrings and patterns in strings . . . . . . . . . . . . . . . . . . . . . . .210
Converting strings between uppercase and lowercase . . . . . . . . . . . .215
Example: ASCII art . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .216
Chapter 7: Working with arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Basics of arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Indexed arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Associative arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Multidimensional arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Cloning arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .241
Advanced topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .241
Example: PlayList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Chapter 8: Handling errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Basics of error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Types of errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Error handling in ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
ActionScript 3.0 error-handling elements . . . . . . . . . . . . . . . . . . . . 260
Error-handling strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Working with the debugger version of Flash Player . . . . . . . . . . . . . . . 261
Handling synchronous errors in an application . . . . . . . . . . . . . . . . . . 262
Creating custom error classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
Responding to error events and status . . . . . . . . . . . . . . . . . . . . . . . . . 268
5
Plik z chomika:
danielozo1
Inne pliki z tego folderu:
Flash_kurs.rar
(538540 KB)
KursFlash.rar
(164175 KB)
kurs flash.zip
(345625 KB)
Kurs-flash.rar
(449307 KB)
Kurs Flash.iso
(604338 KB)
Inne foldery tego chomika:
▣ Instalki
▣ Różne
●Programy Muzyczne
3gp xxx super
50000 Sterowników Do Windows XP
Zgłoś jeśli
naruszono regulamin