0% found this document useful (0 votes)
756 views700 pages

Action Script 3.0 Coding

Uploaded by

bryantws
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
756 views700 pages

Action Script 3.0 Coding

Uploaded by

bryantws
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ACTIONSCRIPT 3.

2007 Adobe Systems Incorporated.

ActionScript 3.0

Adobe Systems Incorporated


Adobe Systems Incorporated


Adobe Systems Incorporated

AdobeAdobe FlexFlex Builder Flash Player Adobe Systems Incorporated /

ActiveX Windows Microsoft Corporation Macintosh Apple


Inc.

Nellymoser, Inc. ([Link])

Sorenson Spark Sorenson Media, Inc.


Opera 1995-2002 Opera Software ASA
Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA
48 C.F.R. 2.101
48 C.F.R. 12.212 48 C.F.R. 227.7202
48 C.F.R. 12.212 48 C.F.R. 227.7202-1 227.7202-4
(a) (b)
Adobe Systems Incorporated, 345 Park Avenue,
San Jose, CA 95110-2704, USA. Adobe
Executive Order 112461974 Vietnam Era Veterans Readjustment Assistance Act 402
(38 USC 4212) 1973 Rehabilitation Act 503 41 CFR 60-1 60-60
60-250 60-741

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1 : ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Flash Player API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2 : ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3 : ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . 55
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .61
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
4 : ActionScript . . . . . . . . . . . . . . . . . . . . . 115
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
(property) (attribute) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
GeometricShapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

5 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .161
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
6 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
7 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
PlayList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
8 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
ECMAScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
[Link] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
CustomErrors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236

9 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .243
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .244
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .246
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .252
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .254
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Wiki . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .262
10 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .268
ActionScript 3.0 . . . . . . . . . . . . 271
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Alarm Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .286
11 : XML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .293
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .294
XML E4X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
XMLList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Internet RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
12 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .324
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .326
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328
DisplayObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .329
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .329

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
DisplayObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .347
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
DisplayObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
SpriteArranger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
13 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .374
Rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .376
Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .379
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
14 : API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .387
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Algorithmic Visual Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400

15 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .403
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .407
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .407
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Filter Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .424
16 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .425
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .425
MovieClip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
ActionScript MovieClip . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
SWF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .433
RuntimeAssetsExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .434
17 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .439
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .442
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .442
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .443
HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .443
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .446
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .448

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .457
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
18 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Bitmap BitmapData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .473
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .476
sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . . .476
19 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .478
Flash (FLV) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
onCuePoint onMetaData . . . . . . . . . . . . . . . . . . . . . . . 486
NetStream client Object . . . . . . . . . . . . . . . .487
. . . . . . . . . . . . . . . . . . . . . 488
NetStream . . . . . . . . . . . . . . . . . . . . 488
NetStream . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
NetStream client this . . . . . . . . . . . . . . . . . . . . . . . 491
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .496
Camera . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .496
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .497
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .497
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .497
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .498
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Flash Player FLV . . . . . . . . . . . . . . . . . . . . . . . . 503
FLV . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Macintosh FLV . . . . . . . . . . . . . . . . . 505
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
20 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .522
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .523
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .524
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .525
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .526
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .528
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .532
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .532
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .533
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .533
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .534
. . . . . . . . . . . . . . . . . . . . . . . . . .535
Podcast Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .535
RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .536
SoundFacade . . . . . . . . . . . . . . . . . . . . . . . 537
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Podcast Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541

10

21 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .547
WordSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
22 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .557
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .572
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .576
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Telnet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
23 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
ApplicationDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
IME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .611
24 : . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
25 : API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .627
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
ExternalInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
API XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
API ActiveX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642

11

26 : Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . .649


Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .652
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .662
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .664
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .665
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .668
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
SWF . . . . . . . . . . . . . . . . . . . . . . . . . . 676
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
LocalConnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
. . . . . . . . . . . . . . . . . . . . . . . . . 680
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683

12


ActionScript 3.0

ActionScript 1.0 ActionScript 2.0

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16

ActionScript

1-4 ActionScript

ActionScript 3.0
ECMAScript 4
ActionScript Adobe
Flash Player 9

5-10 ActionScript 3.0

ActionScript 3.0
ECMAScript

11-26 Flash Player API

Adobe Flash Player 9

Adobe Flash CS3 Professional


ActionScript 3.0

13

ActionScript 3.0

Adobe Flex

Flex Builder

Builder 2

Adobe Flash CS3 Professional

ActionScript 1 ActionScript

3.0

ActionScript
Flex Builder Flash
ActionScript 3.0 14
ActionScript

ActionScript
ActionScript 3.0

ActionScript 3.0 ActionScript 3.0

ActionScript 3.0
ActionScript 3.0

ActionScript 3.0
ActionScript 3.0 Flash fl
Flash Player API Flash

Flash
Flash

Flash

Flash Web

ActionScript

3.0

ActionScript 3.0 Flash Player


API

ActionScript

3.0

Flash ActionScript 3.0 API

ActionScript 3.0

14

Flash

Adobe Flash ActionScript 2.0

ActionScript

ActionScript 2.0

ActionScript

2.0

Flash

Flash

2.0

Lite 2.x

Flash Lite 2.x

ActionScript 2.0
ActionScript 2.0
Flash ActionScript 2.0 API

ActionScript 2.0
Flash
2 Adobe
API
JavaScript API
Adobe Flash Lite 2.x
Flash Lite 2.x
ActionScript
Flash Lite 2.x

Flash Lite

2.x ActionScript

Flash Lite 2.x


Flash Lite 2.x
ActionScript

Flash Lite

2.x ActionScript

Flash Lite 2.x ActionScript 2.0


API

Flash

Lite 1.x

Flash Lite 1.x Adobe Device


Central CS3

Flash Lite 1.x

Flash Lite 1.x

Flash Lite 1.x ActionScript

Flash Lite 1.x


ActionScript Flash Lite 1.x
ActionScript

Flash Lite

1.x ActionScript

Flash Lite 1.x ActionScript

ActionScript

15

ActionScript
Adobe

Adobe Adobe

Adobe
Adobe ActionScript
[Link]/devnet/

Adobe

[Link]/
designcenter/

16

ActionScript 3.0
ActionScript

ActionScript 3.0

ActionScript. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21

ActionScript
ActionScript Adobe Flash Player Flash

ActionScript Flash Player ActionScript (AVM) ActionScript



Adobe Flash CS3 Professional Adobe Flex Builder
Adobe Flex SDK Flex Data Services SWF
SWF Flash Player

ActionScript 3.0
ActionScript 3.0

ActionScript AVM2

ECMAScript

(ECMA 262)

ECMAScript (ECMA-262) 4

(API)

17

ECMAScript for XML (E4X) ECMA-357 2 XML API


E4X ECMAScript XML

(DOM) 3

ActionScript 3.0
ActionScript 3.0 ActionScript
ActionScript 3.0
Adobe Flash Player 9 AVM2
ActionScript 3.0 ActionScript 10
ActionScript AVM1 ActionScript 1.0 ActionScript 2.0
Flash Player 9 AVM1
21

ActionScript 3.0
ActionScript 3.0 ActionScript
ActionScript 3.0 ActionScript ActionScript 3.0
Flash Player
API

ActionScript 3.0

ActionScript 3.0 ActionScript

ActionScript 2.0
ActionScript 3.0 Flash
Player 9

18

ActionScript 3.0


ActionScript 3.0

dynamic ActionScript 3.0


dynamic

ActionScript 3.0
ActionScript 2.0
[Link]

ECMAScript for XML (E4X)


ActionScript 3.0 ECMAScript for XML (E4X) ECMA-357
E4X XML XML API
E4X XML E4X
XML ActionScript 3.0 E4X
293 11 XML
ECMA E4X [Link]

ActionScript 3.0
ECMAScript (ECMA-262) 3
ActionScript 3.0

public private protected

(URI) E4X XML

ActionScript 2.0 Number ActionScript 3.0


int uint int 32 ActionScript
CPU int
uint 32 RGB

ActionScript 3.0

19

Flash Player API


ActionScript 3.0 Flash Player API

DOM3
3 (DOM3)

DOM 3 ActionScript

[Link] Flash
API Flash

Flash Player

API
Flash Player
Flash

API Flash

Sprite MovieClip UI
Shape new

Flash
z

Player

ActionScript 3.0 Flash


API Loader SWF
URLLoader
Socket
/ /

20

ActionScript 3.0


API ActionScript
URLStream URLLoader
ByteArray
Sound API SoundChannel SoundMixer
API SWF

ActionScript 3.0 API [Link] TextLineMetrics


ActionScript 2.0
[Link]() TextField
getCharBoundaries()
getCharIndexAtPoint()
getFirstCharInParagraph()
getLineLength() getLineText()
Font SWF

Flash Player Flash Player 9


Flash Player Flash Player 9
ActionScript 3.0 Flash Player 9

SWF

ActionScript 1.0 2.0 ActionScript 3.0

ActionScript 3.0 ActionScript


SWF

1.0 2.0 SWF

ActionScript 1.0 2.0 SWF ActionScript 3.0


SWF Flash 8 Flex Builder 1.5 SWF
ActionScript 3.0 SWF
ActionScript 2.0 SWF
ActionScript 2.0 SWF ActionScript 3.0 SWF
ActionScript 2.0 SWF loadMovieNum() 0
level

21

ActionScript 1.0 2.0 SWF ActionScript 3.0


SWF ActionScript 2.0
ActionScript 2.0
ActionScript 3.0
ActionScript 3.0

ActionScript 3.0
ActionScript 2.0

Flash Player
ActionScript SWF

SWF
AVM
ActionScript
SWF

Flash Player 7

Flash Player 8

Flash Player 9

AVM1

AVM1

AVM1 AVM2

1.0 2.0

1.0 2.0

1.0 2.0 3.0

ActionScript 1.0 2.0

ActionScript 3.0

ActionScript 1.0 2.0

ActionScript 1.0 2.0


ActionScript 3.0

ActionScript 1.0 2.0

ActionScript 3.0

Flash Player 9 Flash Player 8


ActionScript 1.0 2.0

ActionScript 3.0

ActionScript 1.0 2.0

22

ActionScript 3.0

ActionScript
ActionScript
ActionScript
ActionScript

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

ActionScript
ActionScript

ActionScript

23

xy

x 200 y 150
x y

value1 value2

value1 + value2

ActionScript 3.0

ActionScript

ActionScript var
var value1:Number;

value1 Number
Number ActionScript

var value2:Number = 17;

24

ActionScript

Adobe Flash CS3 Professional



Flash ActionScript

rocketShip ActionScript rocketShip

ActionScript

String
Numeric numeric ActionScript 3.0

Number

Int

Uint

Boolean true false


ActionScript

Date

Date

MovieClip
TextField
SimpleButton
Date


Example A
B C MovieClip
MovieClip

myVariable

myVariable

Number
Number
myVariable Number
myVariable Number

25


ActionScript


Flash

ActionScript MovieClip


x alpha
Flash
Flash
ActionScript MovieClip

ActionScript

Song artist
title MovieClip rotation x width alpha

ActionScript square
100 x

MovieClip

square.x = 100;

rotation square MovieClip triangle MovieClip

[Link] = [Link];

square

MovieClip 1.5

[Link] = 1.5;

26

ActionScript

square triangle
(.) x rotation scaleX
- -

Flash

shortFilm

MovieClip

[Link]();

shortFilm

MovieClip

[Link]();

shortFilm

MovieClip 1

[Link](1);




gotoAndStop()
play() stop()


Number toString()

var numericData:Number = 9;
var textData:String = [Link]();

Number toString()
TextField text String
numericData
calculatorDisplay TextField
[Link] = [Link]();

27

ActionScript

ActionScript

ActionScript
ActionScript Adobe Flash Player
Flash Player ActionScript


ActionScript

Loader
Flash Player

ActionScript

function eventResponse(eventObject:EventType):void
{
//
}
[Link](EventType.EVENT_NAME, eventResponse);

addEventListener()

eventResponse
eventObject
ActionScript
({ ...})

28

ActionScript


addEventListener()
addEventListener() addEventListener()

myButton

function eventResponse(event:MouseEvent):void
{
//
}
[Link]([Link], eventResponse);

Flash Player
1.

SWF Flash

Player eventResponse()

29

2.

Flash Player
myButton addEventListener()
eventResponse

a. myButton
addEventListener() myButton eventResponse()

30

ActionScript

3. myButton click
[Link]

a.

Flash Player MouseEvent


Event MouseEvent

31

b.

Flash Player myButton


eventResponse()
Player eventResponse()

myButton Flash

c. eventResponse()

32

ActionScript

playButton
this
[Link]();
function playMovie(event:MouseEvent):void
{
[Link]();
}
[Link]([Link], playMovie);

entryText
outputText
function updateOutput(event:TextEvent):void
{
var pressedKey:String = [Link];
[Link] = "You typed: " + pressedKey;
}
[Link](TextEvent.TEXT_INPUT, updateOutput);

URL linkButton
function gotoAdobeSite(event:MouseEvent):void
{
var adobeURL:URLRequest = new URLRequest("[Link]
navigateToURL(adobeURL);
}
[Link]([Link], gotoAdobeSite);

ActionScript

33

ActionScript Flash

Flash
Adobe Flex Builder Adobe Macromedia MXML
MXML
ID MXML Flex ID
ActionScript
ActionScript
ActionScript
ActionScript


var someNumber:Number = 17.239;
var someNegativeInteger:int = -53;
var someUint:uint = 22;


var firstName:String = "George";
var soliloquy:String = "To be or not to be, that is the question...";

true false
var niceWeather:Boolean = true;
var playingOutside:Boolean = false;

XML XML
var employee:XML = <employee>
<firstName>Harold</firstName>
<lastName>Webster</lastName>
</employee>;

ActionScript Array RegExp Object Function


189 243
80 Object
new

var raceCar:MovieClip = new MovieClip();


var birthday:Date = new Date(2006, 7, 9);

34

ActionScript

new

new

var someNumber:Number = 6.33;


var someNumber:Number = new Number(6.33);

new ClassName()
ActionScript Flash
Flex Builder MXML new
ActionScript
Flash new
430 ActionScript MovieClip

ActionScript

(+)
var sum:Number = 23 + 32;

(*)
var energy:Number = mass * speedOfLight * speedOfLight;

(==)

true false

if (dayOfWeek == "Wednesday")
{
takeOutTrash();
}

if

90

35


ActionScript

ActionScript

//
var age:Number = 10; // age 10

(/*) (*/)

/*

*/


ActionScript

ActionScript

102

100

if if
true

if (age < 20)


{
//
}

36

ActionScript

else if true
if (username == "admin")
{
//
}
else
{
//
}

97

ActionScript
ActionScript

URL

1.

FLA ActionScript

2.
3.

ActionScript

4.

FLA
FLA

FLA
1.
FLA
FLA
2.

1 2

37

3.

buttons

4.

buttons
ActionScript

actions

FLA
1. buttons play

2.
3. >
4.
5. playButton
6. 1 5 homeButton

ActionScript

SWF 1

SWF

URL

1
1. actions 1
2. >
3.
stop();

38

ActionScript


1.
2.
function startMovie(event:MouseEvent):void
{
[Link]();
}

startMovie() startMovie()

3.
[Link]([Link], startMovie);

startMovie() playButton click


playButton startMovie()
URL
1.
2.
function gotoAuthorPage(event:MouseEvent):void
{
var targetURL:URLRequest = new URLRequest("[Link]
navigateToURL(targetURL);
}

gotoAuthorPage() URL
[Link] URLRequest URL navigateToURL()
URL
3.
[Link]([Link], gotoAuthorPage);

gotoAuthorPage() homeButton click


homeButton gotoAuthorPage()

1. >Flash SWF Flash

Player

2.

39

3.

addEventListener()

addEventListener()

MouseEvent



SWF

ActionScript
ActionScript
ActionScript
ActionScript ActionScript
ActionScript

ActionScript 3.0

ActionScript

Flash
Flash

ActionScript

ActionScript Flash
MovieClip

1 Flash
Flash ActionScript Flash FLA
Flash

Flash ActionScript
ActionScript .as

40

ActionScript

ActionScript
ActionScript ActionScript
.as ActionScript

ActionScript ActionScript
MXML
ActionScript include Adobe Flex MXML <mx:Script>
ActionScript ActionScript include
ActionScript
Flex MXML <mx:Script>
ActionScript
[Link] ActionScript
<mx:Script source=[Link] />

ActionScript ActionScript
ActionScript
ActionScript

import ActionScript
ActionScript MovieClip

import [Link];

import

MovieClip

import [Link].*;

Flash flash.*
Flash fl.* Flex

ActionScript
Box
Box
var smallBox:Box = new Box(10,20);

Box Box

ActionScript

41



ActionScript

Flash
Adobe Flash CS3 Professional ActionScript
FLA ActionScript
Flash
ActionScript
Flash
ActionScript SWF
Flash

Adobe Flash CS3 Professional ActionScript

FLA
ActionScript

ActionScript (.as)

Flex Builder
Adobe Flex Builder Flex MXML
Flex Builder ActionScript
Flex ActionScript Flex

Flex
SWF Flash
Flex Internet
ActionScript MXML Flex
Builder

42

ActionScript

ActionScript
ActionScript (.as)
ActionScript Adobe ActionScript
ActionScript
MXML ActionScript Flex SDK Flex Flex
SWF Flex ActionScript
ActionScript ActionScript
Flash
ActionScript

ActionScript

ActionScript HTML
ActionScript

Flash

Flex SDK
Flex

Flash Flex Builder ActionScript

ActionScript

Adobe Dreamweaver CS3


ASDT
FDT
FlashDevelop
PrimalScript
SE|PY
Xcode ActionScript

ActionScript
ActionScript
ActionScript 3.0
1.

ActionScript 3.0
FlashFlex BuilderDreamweaver ActionScript
Flash Flex
Flash FLA
ActionScript Flex
MXML ActionScript

2.

3.

ActionScript

43

4.

ActionScript
Flash Flex

1 3
ActionScript 2 4

ActionScript 4

1.



Song Playlist

2.
3.

44

ActionScript

4.

5.

Sprite MovieClipMovieClip
Sprite
134

ActionScript
1.

ActionScript Flex Builder Flash


Dreamweaver

2. class public class


public class MyClass
{
}

public 120

45

3.

package package
class

package mypackage
{
public class MyClass
{
}
}

4. var

public
textVariable numericVariable dateVariable
public var textVariable:String = "some default value";
public var numericVariable:Number = 17;
public var dateVariable:Date;

5.

myMethod()
public function myMethod(param1:String, param2:Number):void
{
//
}

public function MyClass()


{
//
//
textVariable = "Hello there!";
dateVariable = new Date(2001, 5, 11);
}



127 get set

ActionScript EventDispatcher

267 10

46

ActionScript


ActionScript ActionScript 3.0
ActionScript 3.0
.as

Adobe

Flash Flex Builder Dreamweaver


ActionScript

.as

ActionScript 3.0 Flash Flex Builder

Flash Flex Builder 2


ActionScript 3.0 Flash Flex
ActionScript 3.0

ActionScript

(UML)
ActionScript
ActionScript Hello

HelloWorld

Hello

World

World!
Greeter Flash
Flex

47

HelloWorld Greeter
Hello World
Greeter Flex Builder Flash

Flash Greeter
1. Flash >
2. ActionScript

ActionScript
3. >

ActionScript

[Link]
48 Greeter

Greeter
Greeter Greeter HelloWorld
Greeter
1.
package
{
public class Greeter
{
public function sayHello():String
{
var greeting:String;
greeting = "Hello World!";
return greeting;
}
}
}

Greeter sayHello() Hello


2. > ActionScript
Greeter Flash Flex

48

ActionScript

ActionScript
Greeter
Flash Flex

HelloWorld Greeter Greeter

Flash ActionScript
1. >
2. Flash

Flash
3. >

[Link] Flash

[Link]
4.

Flash
300 100

5. mainText

6.

7.
var myGreeter:Greeter = new Greeter();
[Link] = [Link]("Bob");

8.

49 ActionScript

ActionScript

Flash Flex Builder

HelloWorld
Flash ActionScript
Flash >
ActionScript HelloWorld

1.

2.

[Link]

[Link]

49

3.

Hello,

Hello World Flash Player

Bob

50 HelloWorld

ActionScript 3.0

HelloWorld

Greeter Flex

Flash

[Link]
1. [Link]
2.
package
{
public class Greeter
{
/**
* Defines the names that should receive a proper greeting.
*/
public static var validNames:Array = ["Sammy", "Frank", "Dean"];
/**
* Builds a greeting string using the given name.
*/
public function sayHello(userName:String = ""):String
{
var greeting:String;
if (userName == "")
{
greeting = "Hello. Please type your user name, and then press the
Enter key.";
}
else if (validName(userName))
{
greeting = "Hello, " + userName + ".";
}
else
{
greeting = "Sorry, " + userName + ", you are not on the list.";
}
return greeting;
}

50

ActionScript

/**
* Checks whether a name is in the validNames list.
*/
public static function validName(inputName:String = ""):Boolean
{
if ([Link](inputName) > -1)
{
return true;
}
else
{
return false;
}
}
}
}

Greeter

validNames

Greeter

sayHello() userName

("") greeting
"Hello, userName"
greeting "Sorry, userName, you are not on the list."

validNames inputName validName() true


false [Link](inputName) inputName
validNames [Link]()
-1

ActionScript

Flash Flex

Flash
1. [Link]
2.

1 ("") Greeter sayHello()

var myGreeter:Greeter = new Greeter();


[Link] = [Link]("");

3.

mainText
4.
5.

User Name:
InputText

textIn
6.

51

7.
[Link] = true;
[Link] = true;
[Link](KeyboardEvent.KEY_UP, keyPressed);
function keyPressed(event:Event):void
{
if ([Link] == [Link])
{
[Link] = [Link]([Link]);
}
}

textIn
addEventListener()
Enter
keyPressed() myGreeter sayHello() textIn

greeting
mainText text
1
[Link] = true;
[Link] = true;
var myGreeter:Greeter = new Greeter();
[Link] = [Link]("");
[Link](KeyboardEvent.KEY_UP, keyPressed);
function keyPressed(event:Event):void
{
if ([Link] == [Link])
{
[Link] = [Link]([Link]);
}
}

8.
9. >

Sammy Frank
Dean hello

52

ActionScript


Hello World ActionScript

3.0

Flex Builder Flash

Flash
Flash
Flash

1.

2.


outputText appendText()

3. trace()
4. trace()

appendText()
5. >

SWF

trace()

trace() ActionScript trace()

trace()

trace() trace()

var albumName:String = "Three for the money";

53

trace()

var albumName:String = "Three for the money";


trace("albumName =", albumName);

albumName = Three for the money

trace()
trace() trace()

trace()

TextField appendText()
ActionScript
outputText albumName

var albumName:String = "Three for the money";


[Link]("albumName = ");
[Link](albumName);

outputText
albumName = Three for the money

appendText()
appendText()
("\n")
[Link]("\n"); // adds a line break to the text field

trace() appendText()

toString()
var albumYear:int = 1999;
[Link]("albumYear = ");
[Link]([Link]());

Hello World
ActionScript 3.0

54

ActionScript

ActionScript
ActionScript 3.0 ActionScript Adobe Flash Player
(API) ActionScript ActionScript ECMAScript
(ECMA-262) 4 Flash Player API Flash Player
ActionScript

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

55


ActionScript 3.0 ActionScript 3.0

ActionScript 3.0
Java C++ (OOP)
ECMAScript 4
ActionScript 3.0 ECMAScript

Java C++ ECMAScript


ActionScript 3.0 Java C++
ActionScript

ActionScript 3.0 getter-setter

ActionScript Java C++ ActionScript


ActionScript
Java C++

ActionScript Java C++ ActionScript


ActionScript
ActionScript 3.0

ActionScript
ActionScript
__proto__ __resolve
Flash Player

56

ActionScript


ActionScript 3.0

ActionScript Number
Boolean String ActionScript Array Math
XML ECMAScript
Object ActionScript
Object
ActionScript 2.0
Object
var someObj:Object;
var someObj;

ActionScript

3.0

var someObj:*;
var someObj;

Object
undefined Object
class
(property) const var get set
(attribute) getter setter (property) function
new

Date

myBirthday

var myBirthday:Date = new Date();

57


ActionScript 3.0

package
package samples
{
public class SampleCode
{
public var sampleGreeting:String;
public function sampleFunction()
{
trace(sampleGreeting + " from sampleFunction()");
}
}
}

SampleCode samples
[Link]
sampleGreeting sampleFunction()
[Link] [Link]()
Java
ActionScript 3.0

public internal Java


ActionScript 3.0
ActionScript 3.0 Java
(.) Java

SampleCode

Flash Player
API [Link] [Link] Flash
[Link] ActionScript XML
[Link] XML XML
XML ActionScript 3.0 XML for ECMAScript (E4X)

58

ActionScript

XML XML
[Link] XML ([Link])
XML XMLDocument

package
{
class
class
class
}

[Link]
XMLDocument {}
XMLNode {}
XMLSocket {}

Flash Player API flash [Link]


API [Link]

ActionScript 3.0 ActionScript


ActionScript 3.0

ActionScript 3.0 ActionScript


package
ActionScript 3.0
ActionScript 3.0 package

public internal
public

59

ActionScript 2.0
SampleCode
SampleCode

ActionScript 2.0

samples

import samples.*;

import [Link];

import samples SampleCode


SampleCode

(SampleCode)

([Link])

SampleCode

var mySample:[Link] = new [Link]();

SampleCode

var mySample:SampleCode = new SampleCode();

internal

public SampleCode CodeFormatter


// [Link]
package samples
{
public class SampleCode {}
}
// [Link]
package samples
{
class CodeFormatter {}
}

60

ActionScript

SampleCode public CodeFormatter


samples samples CodeFormatter

import [Link];
import [Link];
var mySample:SampleCode = new SampleCode(); // public
var myFormatter:CodeFormatter = new CodeFormatter(); //

public public

SampleCode
package [Link]
{
public class SampleCode {}
}

SampleCode
import [Link];
import [Link];
var mySample:SampleCode = new SampleCode(); //

SampleCode

var sample1:[Link] = new [Link]();


var sample2:[Link] = new [Link]();

C++ import #include #include C++


C++
ActionScript 3.0 include
ActionScript 3.0 import

public private protected


internal

XML
ActionScript XML

61


sampleGreeting
sampleFunction()
class SampleCode
{
var sampleGreeting:String;
function sampleFunction () {
trace(sampleGreeting + " from sampleFunction()");
}
}

internal

internal
public
sampleGreeting sampleFunction() internal
namespace
version1
namespace version1;


myFunction() version1
version1 function myFunction() {}

use
use myFunction()
use namespace version1;
myFunction();

myFunction()
version1::myFunction();

URI

(URI)

XML
URI URI URI

namespace flash_proxy = [Link]

62

ActionScript

URI URI
URI

namespace flash_proxy;

URI URI

[Link]
flash_proxy flash_proxy
[Link]
package [Link]
{
namespace flash_proxy;
}

public flash_proxy
package [Link]
{
public namespace flash_proxy;
}


public public
public
public
example1
myFunction() example1

namespace example1;
class someClass
{
example1 myFunction() {}
}

63

myFunction() example1
example1

10 10

public
private protected internal

public private protected internal

private

use namespace (::)


use namespace
example1 use
namespace example1
use namespace example1;
myFunction();

use namespace

use namespace
example1 myFunction()
example1::myFunction();

64

ActionScript


Flash Player API [Link]
Proxy ActionScript 2.0 Object.__resolve
Proxy
flash_proxy
flash_proxy Proxy Proxy
Proxy
Proxy
Proxy Proxy callProperty()

Proxy flash_proxy
Flash Player API flash_proxy Proxy
flash_proxy Proxy
flash_proxy

[Link]

package [Link]
{
public namespace flash_proxy;
}

Proxy

Proxy

public class Proxy


{
flash_proxy function callProperty(name:*, ... rest):*
flash_proxy function deleteProperty(name:*):Boolean
...
}

Proxy flash_proxy
Proxy dynamic
callProperty() flash_proxy
package
{
import [Link];
import [Link].flash_proxy;
dynamic class MyProxy extends Proxy
{
flash_proxy override function callProperty(name:*, ...rest):*
{
trace("method call intercepted: " + name);
}
}
}

65

MyProxy
testing() Proxy callProperty()
trace()
var mySample:MyProxy = new MyProxy();
[Link](); //

Proxy flash_proxy
Proxy Proxy
12
Proxy Proxy
flash_proxy
callProperty()
callProperty()
dynamic class MyProxy extends Proxy
{
public function callProperty() {}
flash_proxy override function callProperty(name:*, ...rest):*
{
trace("method call intercepted: " + name);
}
}

publicprivateinternal protected

use namespace

([Link]) myInternal example


example public

// example [Link]
package example
{
public namespace myInternal = "[Link]
examples";
}

66

ActionScript

([Link]) ([Link])
Utility [Link] example
alpha Helper [Link] example
beta [Link] [Link]

// example/alpha [Link]
package [Link]
{
import [Link];
public class Utility
{
private static var _taskCounter:int = 0;
public static function someTask()
{
_taskCounter++;
}
myInternal static function get taskCounter():int
{
return _taskCounter;
}
}
}
// example/beta [Link]
package [Link]
{
import [Link];
public class Helper
{
private static var _timeStamp:Date;
public static function someTask()
{
_timeStamp = new Date();
}
myInternal static function get lastCalled():Date
{
return _timeStamp;
}
}
}

67

([Link]) example
Adobe Flash CS3 Professional FLA NamespaceUseCase
myInternal
myInternal

// [Link]
package
{
import [Link];
import [Link];
import [Link];
import [Link];

//
// Utility
// Helper

public class NamespaceUseCase extends MovieClip


{
public function NamespaceUseCase()
{
use namespace myInternal;
[Link]();
[Link]();
trace([Link]); // 2
[Link]();
trace([Link]);

// [ someTask() ]

}
}
}

var
ActionScript 2.0 var ActionScript 3.0
var ActionScript i
var i;

var
i
i; // i

(:) int i
var i:int;

68

ActionScript

(=) i 20
var i:int;
i = 20;

var i:int = 20;

var numArray:Array = ["zero", "one", "two"];

new CustomClass
customItem
var customItem:CustomClass = new CustomClass();

(,)
3
var a:int, b:int, c:int;

3 ab c

var a:int = 10, b:int = 20, c:int = 30;



ActionScript 3.0

strGlobal

var strGlobal:String = "Global";


function scopeTest()
{
trace(strGlobal); //
}
scopeTest();
trace(strGlobal); //

69



localScope() str2
function localScope()
{
var strLocal:String = "local";
}
localScope();
trace(strLocal); // strLocal


str1 scopeTest()
trace trace

var str1:String = "Global";


function scopeTest ()
{
var str1:String = "Local";
trace(str1); //
}
scopeTest();
trace(str1); //

C++ Java ActionScript


({) (}) C++ Java

ActionScript

function blockTest (testArray:Array)


{
var numElements:int = [Link];
if (numElements > 0)
{
var elemStr:String = "Element #";
for (var i:int = 0; i < numElements; i++)
{
var valueStr:String = i + ": " + testArray[i];
trace(elemStr + valueStr);
}
trace(elemStr, valueStr, i);
//
}
trace(elemStr, valueStr, i); // numElements > 0
}
blockTest(["Earth", "Moon", "Sun"]);

70

ActionScript



num trace()
num
trace(num); // NaN
var num:Number = 10;
trace(num); // 10

num trace() NaN


NaN Number

num = 5;
trace(num); // 5
var num:Number = 10;
trace(num); // 10

Boolean

false

int

Number

NaN

Object

null

String

null

uint

undefined

null

Number NaN NaN

IEEE-754

*
undefined

Boolean Number int uint


Flash Player API

null

71

BooleanNumberint uint null null


Object
null undefined Object null
Number isNaN()
true false

Boolean
true false Boolean ActionScript 3.0
String Number Array
ActionScript 3.0
Boolean int Number String uint
ActionScript

ActionScript

ArrayDateError
Function RegExp XML XMLList
Java int
[Link] Java
ActionScript 3.0
Flash Player

var someInt:int = 3;
var someInt:int = new int(3);

ActionScript 3.0
ActionScript 3.0 new
Array
var someArray:Array = [1, 2, 3]; //
var someArray:Array = new Array(1,2,3); // Array

72

ActionScript


C++ Java
Smalltalk PythonActionScript 3.0

Adobe Flash CS3 Professional


Adobe Flex Builder 2 ActionScript

(:)

xParam myParam
function runtimeTest(xParam:String)
{
trace(xParam);
}
var myParam:String = hello;
runtimeTest(myParam);

ActionScript
Object xParam String
Number
function dynamicTest(xParam:Object)
{
if (xParam is String)
{
var myStr:String = xParam; //
trace("String: " + myStr);
}
else if (xParam is Number)
{
var myNum:Number = xParam; //
trace("Number: " + myNum);
}
}

73


(*)
xParam

function dynamicTest(xParam)
{
if (xParam is String)
{
var myStr:String = xParam;
trace("String: " + myStr);
}
else if (xParam is Number)
{
var myNum:Number = xParam;
trace("Number: " + myNum);
}
}
dynamicTest(100)
dynamicTest("one hundred");

ActionScript 3.0
3
3 Array
Flash Player

typeTest() Array
3 3 (Array)

function typeTest(xParam:Array)
{
trace(xParam);
}
var myNum:Number = 3;
typeTest(myNum);
// ActionScript 3.0

74

ActionScript

myNum
Flash Player myNum
3 xParam Array
function typeTest(xParam:Array)
{
trace(xParam);
}
var myNum = 3;
typeTest(myNum);
// ActionScript 3.0

ClassBase final
class ClassBase
{
}

ClassExtender
someString

ClassBase

class ClassExtender extends ClassBase


{
var someString:String;
}

ClassBase ClassExtender

var myClass:ClassBase = new ClassExtender();

ClassExtender someString
ClassBase ActionScript 3.0 myClass

var myClass:ClassBase = new ClassExtender();


[Link] = "hello";
// ActionScript 3.0

75

is
is

ActionScript 3.0
ActionScript instanceof
ActionScript 3.0 instanceof
is instanceof x
instanceof y x y ActionScript 3.0

is

Sprite
mySprite is mySprite Sprite DisplayObject
IEventDispatcher
var mySprite:Sprite = new Sprite();
trace(mySprite is Sprite);
trace(mySprite is DisplayObject);
trace(mySprite is IEventDispatcher);

// true
// true
// true

is mySprite

Sprite DisplayObject

Sprite

DisplayObject is mySprite
IEventDispatcher Sprite IEventDispatcher
EventDispatcher is mySprite

instanceof is
instanceof mySprite Sprite DisplayObject
mySprite IEventDispatcher false
trace(mySprite instanceof Sprite);
// true
trace(mySprite instanceof DisplayObject);
// true
trace(mySprite instanceof IEventDispatcher); // false

as
as

ActionScript 3.0
is as
true null false as is
Sprite DisplayObject IEventDispatcher
Number
var mySprite:Sprite = new Sprite();
trace(mySprite as Sprite); // [Sprite ]
trace(mySprite as DisplayObject); // [Sprite ]
trace(mySprite as IEventDispatcher); // [Sprite ]
trace(mySprite as Number);
// null

as

76

ActionScript

String

dynamic
Protean
dynamic class Protean
{
private var privateGreeting:String = "hi";
public var publicGreeting:String = "hello";
function Protean()
{
trace("Protean instance created");
}
}

Protean
Protean aString
aNumber
var myProtean:Protean = new Protean();
[Link] = "testing";
[Link] = 3;
trace([Link], [Link]); // 3

myProtean myProtean
trace traceProtean()
var myProtean:Protean = new Protean();
[Link] = "testing";
[Link] = 3;
[Link] = function ()
{
trace([Link], [Link]);
};
[Link](); // 3

Protean
Protean this
traceProtean() Protean
[Link] = function ()
{
trace([Link]); // undefined
trace([Link]); // hello
};
[Link]();

77


Boolean int Null Number String uint void ActionScript
Object Array Date Error Function RegExp
XML XMLList

Boolean
Boolean true false Boolean
false

int
int 32 -2,147,483,648 (-231)
2,147,483,647 (231-1) -2,147,483,648 2,147,483,647
ActionScript Number
ActionScript 3.0 32
int Number

int int Number Number


-9,007,199,254,740,992 9,007,199,254,740,992 53
int 0

Null
Null null String
Object BooleanNumberint uint
null Boolean Number int uint null
Flash Player null Null

Number
ActionScript 3.0 Number
Number int uint
32

Number IEEE (IEEE-754) 64


64 1
11 52
2 N N

78

ActionScript

Number Number
Number
64 265-1 11
Number 21023

Number Number Number.MAX_VALUE


Number.MIN_VALUE
Number.MAX_VALUE == 1.79769313486231e+308
Number.MIN_VALUE == 4.940656458412467e-324

Number 52
52 1/3

Number 52 Number
52 -9,007,199,254,740,992 (-253)
9,007,199,254,740,992 (253)

Flash Player NaN Number

NaN Number

0 0 NaN 0

String
String 16 Unicode
UTF-16 Java
String null null
("")

uint
uint 32 0 4,294,967,295 (232-1)
0 4,294,967,295uint
uint int
uint Number
53 uint 0

79

void
void undefined ActionScript undefined
Object ActionScript 3.0 Object null
undefined Object Flash Player null
undefined (*)
void

Object
Object Object Object ActionScript
ActionScript 3.0 Object Object
Object
Object undefined Object
ActionScript 3.0 Object null
ActionScript Object
ActionScript 3.0
Object
(*)
x
var x
var x:*

undefined undefined
Flash Player undefined Object
null undefined Object Flash
Player undefined null

Flash Player
2 Boolean Flash Player 2
true

var myBoolean:Boolean = true;


var myINT:int = int(myBoolean);
trace(myINT); // 1

80

ActionScript

(+)

class A {}
class B extends A {}
var objA:A = new A();
var objB:B = new B();
var arr:Array = new Array();
objA = objB; //
objB = arr; //

var quantityField:String = "3";


var quantity:int = quantityField; //

var quantityField:String = "3";


var quantity:int = int(quantityField); //

81

int uint Number


int uint Number Flash
Player int uint 0 Number
NaN true 1 false 0
var myBoolean:Boolean = true;
var myUINT:uint = uint(myBoolean);
var myINT:int = int(myBoolean);
var myNum:Number = Number(myBoolean);
trace(myUINT, myINT, myNum); // 1 1 1
myBoolean = false;
myUINT = uint(myBoolean);
myINT = int(myBoolean);
myNum = Number(myBoolean);
trace(myUINT, myINT, myNum); // 0 0 0

0x1A
Number()
uint() int()

trace(uint("5"));
trace(uint("-5"));
trace(uint(" 27 "));
trace(uint("3.7"));
trace(int("3.7"));
trace(int("0x1A"));
trace(Number("3.7"));

//
//
//
//
//
//
//

5
4294967291 MAX_VALUE
27
3
3
26
3.7

int() uint() 0 Number()


NaN
0 NaN
trace(uint("5a"));
// 0
trace(uint("ten"));
// 0
trace(uint("17 63")); // 0

ActionScript 3.0 Number() 8


ActionScript 2.0 Number() 0
ActionScript 3.0 Number()
ActionScript 3.0 0 ActionScript

trace(Number("044"));
// ActionScript 3.0 44
// ActionScript 2.0 36

82

ActionScript

var myUInt:uint = -3; // int/Number uint


trace(myUInt); // 4294967293
var myNum:Number = sampleUINT; // int/uint Number
trace(myNum) // 4294967293
var myInt:int = uint.MAX_VALUE + 1; // Number uint
trace(myInt); // 0
myInt = int.MAX_VALUE + 1; // uint/Number int
trace(myInt); // -2147483648

Number int

uint

Number int uint

Boolean

true 1 0

Date

Date 1970 1 1

null

Object

null Number NaN 0

String

Flash Player
Number NaN int uint 0

undefined

Number NaN int uint 0

Boolean
uint int Number Boolean 0
false true Number NaN false
-1 0 1
var myNum:Number;
for (myNum = -1; myNum<2; myNum++)
{
trace("Boolean(" + myNum +") is " + Boolean(myNum));
}

0 false
Boolean(-1) is true
Boolean(0) is false
Boolean(1) is true

83

Boolean null ("")


false true
var str1:String;
trace(Boolean(str1));

// null
// false

var str2:String = "";


trace(Boolean(str2));

//
// false

var str3:String = " "; //


trace(Boolean(str3)); // true

Object Boolean null false


true
var myObj:Object;
// null
trace(Boolean(myObj)); // false
myObj = new Object(); //
trace(Boolean(myObj)); // true

Boolean
Boolean

var myObj:Object = new Object();


var bool:Boolean = myObj;
trace(bool); // true
bool = "random string";
trace(bool); // true
bool = new Array();
trace(bool); // true
bool = NaN;
trace(bool); // false

//

Boolean

Boolean

String

null ("") false true

null

false

Number int uint

NaN 0 false true

Object

null false true

84

ActionScript

String
String
String true "true" false
"false"

Object String null

"null" "[object Object]"

Array String
String

var myArray:Array = ["primary", "secondary", "tertiary"];


trace(String(myArray)); // primary,secondary,tertiary

Date String
Date
var myDate:Date = new Date(2005,6,1);
trace(String(myDate)); // 7 1 [Link] GMT-0700 2005

String

String

Array

Boolean

"true" "false"

Date

Date

null

"null"

Number int uint

Object

null "null" "[object Object]"

ActionScript 3.0

var num1:int;
var Num1:int;

85


(.)

class DotExample
{
public var prop1:String;
public function method1():void {}
}

prop1 method1()
var myDotEx:DotExample = new DotExample();
myDotEx.prop1 = hello;
myDotEx.method1();

EventDispatcher
events flash
events
[Link]

EventDispatcher
[Link]

ActionScript 3.0 ActionScript

17
"hello"
-3
9.4
null
undefined
true
false

([])

86

ActionScript


new Array
ActionScript ObjectArrayStringNumber
int uint XML XMLList Boolean
// new
var myStrings:Array = new Array(["alpha", "beta", "gamma"]);
var myNums:Array = new Array([1,2,3,5,8]);
//
var myStrings:Array = ["alpha", "beta", "gamma"];
var myNums:Array = [1,2,3,5,8];

Object
({}) (:)

new Object

1 2 3 propA propB propC


// new
var myObject:Object = new Object({propA:1, propB:2, propC:3});
//
var myObject:Object = {propA:1, propB:2, propC:3};

172 244
303 XML

(;)

ActionScript 3.0 (())

trace(2 + 3 * 4);
// 14
trace( (2 + 3) * 4); // 20

87

(,)

var a:int = 2;
var b:int = 3;
trace((a++, b++, a+b)); // 7

trace()
trace("hello"); // hello

ActionScript 3.0 C++


Java
(//)

var someNumber:Number = 3; //

(/*) (*/)
/*
*/

ActionScript


ActionScript 3.0
as

break

case

catch

class

const

continue

default

delete

do

else

extends

false

finally

for

function

if

implements

import

in

instanceof

interface

internal

is

native

new

null

package

private

protected

public

return

super

switch

this

throw

88

ActionScript

to

true

try

typeof

use

var

void

while

with


ActionScript 3.0
each

get

set

namespace

include

dynamic

final

native

override

static

ActionScript 3.0
ActionScript 3.0
Adobe
ActionScript
abstract

boolean

byte

cast

char

debugger

double

enum

export

float

goto

intrinsic

long

prototype

short

synchronized

throws

to

transient

type

virtual

volatile

ActionScript 3.0 const

MINIMUM
MAXIMUM
class A
{
public const MINIMUM:int = 0;
public const MAXIMUM:int;
public function A()
{
MAXIMUM = 10;
}
}

89

var a:A = new A();


trace([Link]); // 0
trace([Link]); // 10

MAXIMUM
class A
{
public const MINIMUM:int = 0;
public const MAXIMUM:int;
}
var a:A = new A();
a["MAXIMUM"] = 10; //

Flash Player API ActionScript


(_) MouseEvent

package [Link]
{
public class MouseEvent extends Event
{
public static const CLICK:String
public static const DOUBLE_CLICK:String
public static const MOUSE_DOWN:String
public static const MOUSE_MOVE:String
...
}
}

=
=
=
=

"click";
"doubleClick";
"mouseDown";
"mouseMove";

(+) (*) 2 3 4
(=) 14 sumNumber
var sumNumber:uint = 2 + 3 * 4; // uint = 14

1 (++)
2
(/) 2 3 (?:) 3

90

ActionScript


(+)

trace(5 + 5);
// 10
trace("5" + "5"); // 55

(-)

trace(-3); // -3
trace(7-2); // 5

(*) (+)
ActionScript
(())

var sumNumber:uint = (2 + 3) * 4; // uint == 20



(?:)

(<) (>)

trace(3 > 2 < 1);


// false
trace((3 > 2) < 1); // false

true 3 2 true
1
trace((true) < 1);

true 1
false 1 1

trace(1 < 1); // false

91

trace(3 > (2 < 1)); // true

false 2 1 false
3
trace(3 > (false));

false 0 3
true 3 0
trace(3 > 0); // true

ActionScript 3.0

[] {x:y} () f(x) new x.y x[y] <></> @ :: ..

x++ x--

++x --x + - ~ ! delete typeof void

* / %

+ -

<< >> >>>

< > <= >= as in instanceof is

== != === !==

&

&&

||

?:

= *= /= %= += -= <<= >>= >>>= &= ^= |=

92

ActionScript


Array

Object

E4X

[]

{x:y}

()

f(x)

new

x.y x[y]

<></>

XMLList (E4X)

(E4X)

::

(E4X)

..

XML (E4X)

(E4X)

xNum++
var xNum:Number = 0;
trace(xNum++); // 0
trace(xNum);
// 1

++

--

93


(++) (--)

++xNum
var xNum:Number = 0;
trace(++xNum); // 1
trace(xNum);
// 1

++

--

delete

typeof

void

undefined

94

ActionScript

<<

>>

>>>

<

>

<=

>=

as

in

instanceof

is

95

==

!=

===

!==

&

&&

||

if..else

?:

96

ActionScript

*=

/=

%=

+=

-=

<<=

>>=

>>>=

&=

^=

|=

ActionScript 3.0

if..else
if..else

x
trace()

20 trace()

if (x > 20)
{
trace("x is > 20");
}
else
{
trace("x is <= 20");
}

if else

97

if..else if
if..else if x
20 x
if (x > 20)
{
trace("x is > 20");
}
else if (x < 0)
{
trace("x is negative");
}

if else

if (x > 0)
trace("x
else if (x
trace("x
else
trace("x

is positive);
< 0)
is negative");
is 0");

Adobe
truepositiveNums
1
var x:int;
var positiveNums:int = 0;
if (x > 0)
trace("x is positive");
positiveNums++;
trace(positiveNums); // 1

98

ActionScript

switch
switch
if..else if switch
case
break switch [Link]()

var someDate:Date = new Date();


var dayNum:uint = [Link]();
switch(dayNum)
{
case 0:
trace("Sunday");
break;
case 1:
trace("Monday");
break;
case 2:
trace("Tuesday");
break;
case 3:
trace("Wednesday");
break;
case 4:
trace("Thursday");
break;
case 5:
trace("Friday");
break;
case 6:
trace("Saturday");
break;
default:
trace("Out of range");
break;
}

99


Adobe
({})

for
for for

5 i 0 4
0 4 5 1
var i:int;
for (i = 0; i < 5; i++)
{
trace(i);
}

for..in
for..in for..in

var myObj:Object = {x:20, y:30};


for (var i:String in myObj)
{
trace(i + ": " + myObj[i]);
}
//
// x: 20
// y: 30

var myArray:Array = ["one", "two", "three"];


for (var i:String in myArray)
{
trace(myArray[i]);
}
//
// one
// two
// three

100

ActionScript

for each..in
XML XMLList
for
each..in for..in for each..in

for each..in

var myObj:Object = {x:20, y:30};


for each (var num in myObj)
{
trace(num);
}
//
// 20
// 30

XML

XMLList

var myXML:XML = <users>


<fname>Jane</fname>
<fname>Susan</fname>
<fname>John</fname>
</users>;
for each (var item in [Link])
{
trace(item);
}
/*
Jane
Susan
John
*/

var myArray:Array = ["one", "two", "three"];


for each (var item in myArray)
{
trace(item);
}
//
// one
// two
// three

101

while
while if true for

var i:int = 0;
while (i < 5)
{
trace(i);
i++;
}

while for while


for while
i

do..while
do..while while

do...while

var i:int = 5;
do
{
trace(i);
i++;
} while (i < 5);
// 5

ActionScript 3.0

ActionScript ActionScript 1.0


class class
ActionScript
ActionScript C++ Java

ActionScript

102

ActionScript

(())
trace() Flash Player API

trace(Use trace to help debug your script);

[Link]()
var randomNum:Number = [Link]();

ActionScript 3.0

function

ActionScript

hello

function traceParameter(aParam:String)
{
trace(aParam);
}
traceParameter("hello"); // hello

103

ActionScript
var

(:)

Function

(=)

function

ActionScript

traceParameter
var traceParameter:Function = function (aParam:String)
{
trace(aParam);
};
traceParameter("hello"); // hello

var traceArray:Array = new Array();


traceArray[0] = function (aParam:String)
{
trace(aParam);
};
traceArray[0]("hello");

var function

104

ActionScript

Example methodExpression()
methodStatement()
methodExpression()
class Example
{
var methodExpression = function() {}
function methodStatement() {}
}
var myEx:Example = new Example();
[Link](); //
[Link](); //

([]) (.)

myExample["methodLiteral"]();

147

105


Test functionExp
functionExp() functionExp

dynamic class Test {}


var myTest:Test = new Test();
//
[Link] = function () { trace("Function expression") };
[Link]();
//
delete [Link];
[Link]();
//

delete
stateFunc()
dynamic class Test {}
var myTest:Test = new Test();
//
function stateFunc() { trace("Function statement") }
[Link] = stateFunc;
[Link](); //
delete [Link];
delete stateFunc;
//
stateFunc();
//
[Link](); //

scopeTest()
statementTest(); // statementTest
function statementTest():void
{
trace("statementTest");
}

expressionTest(); //
var expressionTest:Function = function ()
{
trace("expressionTest");
}

106

ActionScript


return

function doubleNum(baseNum:int):int
{
return (baseNum * 2);
}

return return

function doubleNum(baseNum:int):int {
return (baseNum * 2);
trace("after return"); // trace
}

function doubleNum(baseNum:int):int
{
trace("after return");
}

getNameAndVersion()

function getNameAndVersion():String
{
function getVersion():String
{
return "9";
}
function getProductName():String
{
return "Flash Player";
}
return (getProductName() + " " + getVersion());
}
trace(getNameAndVersion()); // Flash Player 9

113

107


ActionScript 3.0 ActionScript

arguments ...(rest)

ActionScript 3.0
BooleanNumberintuint String
passPrimitives()
int xParam yParam
passPrimitives() xValue yValue
xParam yParam int int xValue
yValue xParam yParam
xValue yValue

function passPrimitives(xParam:int, yParam:int):void


{
xParam++;
yParam++;
trace(xParam, yParam);
}
var xValue:int = 10;
var yValue:int = 15;
trace(xValue, yValue);
// 10 15
passPrimitives(xValue, yValue); // 11 16
trace(xValue, yValue);
// 10 15

passPrimitives() xParam yParam xValue


yValue trace xValue yValue
xValue yValue

108

ActionScript


objVar x y
passByRef()

function passByRef(objParam:Object):void
{
objParam.x++;
objParam.y++;
trace(objParam.x, objParam.y);
}
var objVar:Object = {x:10, y:15};
trace(objVar.x, objVar.y); // 10 15
passByRef(objVar);
// 11 16
trace(objVar.x, objVar.y); // 11 16
objParam objVar trace

objParam x y objVar

ActionScript 3.0

function defaultValues(x:int, y:int = 3, z:int = 5):void


{
trace(x, y, z);
}
defaultValues(1); // 1 3 5

arguments
arguments
arguments

arguments

[Link]

[Link]

arguments ...(rest) arguments

109

ActionScript 3.0

arguments
arguments [Link]
traceArgArray()
function traceArgArray(x:int):void
{
for (var i:uint = 0; i < [Link]; i++)
{
trace(arguments[i]);
}
}
traceArgArray(1, 2, 3);
//
//
//
//

1
2
3

[Link]


[Link]

[Link]
var factorial:Function = function (x:uint)
{
if(x == 0)
{
return 1;
}
else
{
return (x * [Link](x - 1));
}
}
trace(factorial(5)); // 120

...(rest) arguments

110

ActionScript

"arguments" arguments
traceArgArray() arguments arguments
arguments
function traceArgArray(x:int, arguments:int):void
{
for (var i:uint = 0; i < [Link]; i++)
{
trace(arguments[i]);
}
}
traceArgArray(1, 2, 3);
//

ActionScript arguments caller


ActionScript 3.0 caller

...(rest)
ActionScript 3.0 ...(rest)

arguments ...(rest)
arguments [Link]
[Link] ...(rest)
[Link]
...(rest) arguments traceArgArray()
function traceArgArray(... args):void
{
for (var i:uint = 0; i < [Link]; i++)
{
trace(args[i]);
}
}
traceArgArray(1, 2, 3);
//
//
//
//

1
2
3

111

...(rest)
traceArgArray() x int ...(rest)
...(rest)
function traceArgArray(x: int, ... args)
{
for (var i:uint = 0; i < [Link]; i++)
{
trace(args[i]);
}
}
traceArgArray(1, 2, 3);
//
// 2
// 3

ActionScript 3.0

clickListener() addEventListener()
addEventListener([Link], clickListener);
[Link]() [Link]()
194

ActionScript
length
[Link]
ActionScript

function traceLength(x:uint, y:uint):void


{
trace("arguments received: " + [Link]);
trace("arguments expected: " + [Link]);
}
traceLength(3, 5, 7, 11);
/*
4
2 */

112

ActionScript

[Link] = 0;
function someFunction():void
{
[Link]++;
}
someFunction();
someFunction();
trace([Link]); // 2

ActionScript 3.0
isNaN() parseInt()

Flash
Player

ActionScript

113

foo()
rectArea() bar() foo() myProduct
bar() x 2 myProduct()
foo() x 40 bar()
160 8
function foo():Function
{
var x:int = 40;
function rectArea(y:int):int //
{
return x * y
}
return rectArea;
}
function bar():void
{
var x:int = 2;
var y:int = 4;
var myProduct:Function = foo();
trace(myProduct(4)); //
}
bar(); // 160


this this
128

114

ActionScript

ActionScript
(OOP) ActionScript OOP
ActionScript 3.0

ActionScript ActionScript 3.0 OOP

ActionScript
OOP

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
GeometricShapes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

(OOP)

115

OOP
OOP

get

set

(Attribute)
private public

(Class)

(Constructor)

(Data type)

(Dot operator) (.) ActionScript



[Link] myProperty myObject

(Enumeration)

(Class hierarchy)

(Inheritance) OOP

(Instance)

(Namespace)

116

ActionScript

trace() 53

ActionScript 1.0 ActionScript Function


ActionScript 2.0 class extends
ActionScript 3.0 ActionScript 2.0
protected internal final override

Java C++ C# ActionScript


ActionScript class
extends public

ActionScript 3.0 ActionScript 2.0


class ({})
Shape visible
public class Shape
{
var visible:Boolean = true;
}

117

ActionScript 2.0
ActionScript 3.0 package
ActionScript 2.0
ActionScript 3.0 BitmapData [Link]
// ActionScript 2.0
class [Link] {}
// ActionScript 3.0
package [Link]
{
public class BitmapData {}
}

ActionScript 3.0

dynamic

final

internal

internal
dynamic (attribute) (property)

dynamic class Shape {}

abstract ActionScript 3.0


private protected

internal internal public


internal

118

ActionScript

API Accessibility

Adobe Flash Player

public final class Accessibility


{
public static function get active():Boolean;
public static function updateProperties():void;
}

public class SampleClass


{
public namespace sampleNamespace;
sampleNamespace function doSomething():void;
}

ActionScript 3.0

hello() trace

function hello():String
{
trace("hola");
}
class SampleClass
{
hello();
trace("class created");
}
//
hola
class created

ActionScript ActionScript 3.0


message
class StaticTest
{
static var message:String = "static variable";
var message:String = "instance variable";
}
//
var myST:StaticTest = new StaticTest();
trace([Link]); //
trace([Link]);
//

119

(property) (attribute)
ActionScript
ActionScript 3.0
getter setter
ActionScript 3.0 (property)
(attribute)

internal

private

protected

public

static

UserDefinedNamespace

ActionScript 3.0 (attribute) (property)


public private protected internal
public (attribute) (property)
public
var const function
private (attribute) (property) (property)
ActionScript 2.0 private (attribute)
(property)
ActionScript 2.0 private
ActionScript 3.0 private

PrivateExample
ActionScript 2.0
([])

class PrivateExample
{
private var privVar:String = "private variable";
}
var myExample:PrivateExample = new PrivateExample();

120

ActionScript

trace([Link]);
//
trace(myExample["privVar"]); // ActionScript 2.0 ActionScript
3.0

ActionScript 3.0 ([Link])



(myExample["privVar"])
private

(.)

([])

dynamic
Flash Player undefined
PrivateExample
dynamic class PrivateExample
{
private var privVar:String = "private variable";
}
var myExample:PrivateExample = new PrivateExample();
trace([Link]);
//
trace(myExample["privVar"]); // undefined

private undefined
private

(.)

undefined

([])

undefined

undefined

protected

(attribute) ActionScript 3.0 (attribute)


(property) protected

ActionScript 2.0 ActionScript 2.0 private


ActionScript 3.0 protected Java protected
Java
protected

121

internal (attribute)

ActionScript 3.0 (attribute) (property)


(attribute)
(attribute) (property)

public

private

protected

Java Java
ActionScript 3.0 internal
(attribute) (property)
internal

static
static (attribute) varconst function

(property)

(attribute) (property)
(property)

140

public
private protected internal 61

var const var


const
89

122

ActionScript


static var const

totalCount MAX_NUM
totalCount MAX_NUM

class StaticVars
{
public static var totalCount:int = 0;
public static const MAX_NUM:uint = 16;
}

StaticVars totalCount MAX_NUM

trace([Link]); // 0
trace(StaticVars.MAX_NUM); // 16

var myStaticVars:StaticVars = new StaticVars();


trace([Link]); //
trace(myStaticVars.MAX_NUM); //

static const StaticVars


MAX_NUM MAX_NUM

// !!
class StaticVars2
{
public static const UNIQUESORT:uint;
function initializeStatic():void
{
UNIQUESORT = 16;
}
}

var const static


Array
length Array
var const getter setter
127 get set

123

function
public function sampleFunction():String {}

public var sampleFunction:Function = function () {}

override final 138


const
var
override final

147


new
Example status status

class Example
{
public var status:String;
public function Example()
{
status = "initialized";
}
}
var myExample:Example = new Example();
trace([Link]); //

public
privateprotected internal

124

ActionScript

super()
super
super()
super super()super super()
throw return
super() super
ExampleEx Example ExampleEx
super() ExampleEx trace()
null status super()
class ExampleEx extends Example
{
public function ExampleEx()
{
trace([Link]);
super();
}
}
var mySample:ExampleEx = new ExampleEx(); // null

return return

super()

static

Date parse()

parse() Date

Date
parse() Date getMonth()getMonth()
Date month

125

this super
this super
ActionScript
140

3.0

static
Array sort()
Array

CustomArray Array CustomArray


arrayCountTotal arrayNumber
getPosition()

public class CustomArray extends Array


{
public static var arrayCountTotal:int = 0;
public var arrayNumber:int;
public function CustomArray()
{
arrayNumber = ++arrayCountTotal;
}
public function getArrayPosition():String
{
return ("Array " + arrayNumber + " of " + arrayCountTotal);
}
}

[Link]
arrayCountTotal getPosition()
arrayCountTotal
ActionScript 3.0 Array
DESCENDING Array
DESCENDING
public class CustomArray extends Array
{
public function testStatic():void
{
trace(DESCENDING); // 2
}
}

126

ActionScript

this this

class ThisTest
{
function thisValue():ThisTest
{
return this;
}
}
var myTest:ThisTest = new ThisTest();
trace([Link]() == myTest); // true

override final override


final 138

get set
get set getter setter
get set

getPropertyName()
setPropertyName()getter setter

GetSet publicAccess() get


privateProperty

set

class GetSet
{
private var privateProperty:String;
public function get publicAccess():String
{
return privateProperty;
}
public function set publicAccess(setValue:String):void
{
privateProperty = setValue;
}
}

privateProperty
var myGetSet:GetSet = new GetSet();
trace([Link]); //

127

GetSet publicAccess
privateProperty private get set
GetSet publicAccess privateProperty
var myGetSet:GetSet = new GetSet();
trace([Link]); // null
[Link] = "hello";
trace([Link]); // hello

getter setter
var getter setter
getter setter override


ActionScript 3.0

this
this this

this this
ActionScript this
ActionScript this
ActionScript 2.0 this
ActionScript 3.0
this

ThisTest foo()
bar() ThisTest
bar() myFunc
class ThisTest
{
private var num:Number = 3;
function foo():void //
{
trace("foo's this: " + this);
trace("num: " + num);
}
function bar():Function
{
return foo; //
}
}

128

ActionScript

var myTest:ThisTest = new ThisTest();


var myFunc:Function = [Link]();
trace(this); // [ ]
myFunc();
/*
foo's this: [object ThisTest]
output: num: 3 */

this foo()
this ThisTest myFunc
ThisTest ActionScript 2.0 this
num undefined
addEventListener()
281

ActionScript 3.0
C++ enum Java Enumeration
Flash Player API PrintJob
PrintJobOrientation "landscape" "portrait"

public final class PrintJobOrientation


{
public static const LANDSCAPE:String = "landscape";
public static const PORTRAIT:String = "portrait";
}

final

var pj:PrintJob = new PrintJob();


if([Link]())
{
if ([Link] == [Link])
{
...
}
...
}

129

Flash Player API Stringint uint

ActionScript

if ([Link] == [Link]) //

if ([Link] == "portrai") //

public final class Day


{
public static const MONDAY:Day = new Day();
public static const TUESDAY:Day = new Day();
public static const WEDNESDAY:Day = new Day();
public static const THURSDAY:Day = new Day();
public static const FRIDAY:Day = new Day();
public static const SATURDAY:Day = new Day();
public static const SUNDAY:Day = new Day();
}

Flash Player API

function getDay():Day
{
var date:Date = new Date();
var retDay:Day;
switch ([Link])
{
case 0:
retDay = [Link];
break;
case 1:
retDay = [Link];
break;
case 2:
retDay = [Link];
break;
case 3:
retDay = [Link];
break;
case 4:
retDay = [Link];

130

ActionScript

break;
case 5:
retDay = [Link];
break;
case 6:
retDay = [Link];
break;
}
return retDay;
}
var dayOfWeek:Day = getDay();

Day
toString()
Day

ActionScript 3.0
SWF
SWF

Flash
FLA

PianoMusic
var piano:PianoMusic = new PianoMusic();
var sndChannel:SoundChannel = [Link]();

Flash Player API


IEventDispatcher IEventDispatcher
IEventDispatcher

public interface IEventDispatcher


{
function addEventListener(type:String, listener:Function,
useCapture:Boolean=false, priority:int=0,
useWeakReference:Boolean = false):void;
function removeEventListener(type:String, listener:Function,

131

useCapture:Boolean=false):void;
function dispatchEvent(event:Event):Boolean;
function hasEventListener(type:String):Boolean;
function willTrigger(type:String):Boolean;
}

Flash Player API EventDispatcher IeventDispatcher


IEventDispatcher EventDispatcher

public class EventDispatcher implements IEventDispatcher


{
function dispatchEvent(event:Event):Boolean
{
/* */
}
...
}

IEventDispatcher EventDispatcher
IeventDispatcher

is
as

getter setter interface


IExternalizable Flash Player API [Link] IExternalizable

public interface IExternalizable


{
function writeExternal(output:IDataOutput):void;
function readExternal(input:IDataInput):void;
}

132

ActionScript

IExternalizable public public


internal

Flash Player API I

IExample IExternalizable
public interface IExample extends IExternalizable
{
function extra():void;
}

IExample extra() Iexternalizable


writeExternal() readExternal()

ActionScript 3.0 implements


IAlpha IBeta
Alpha
interface IAlpha
{
function foo(str:String):String;
}
interface IBeta
{
function bar():void;
}
class Alpha implements IAlpha, IBeta
{
public function foo(param:String):String {}
public function bar():void {}
}

public

133

[Link]() param
public function foo(param:String):String {}

[Link]() str
function foo(str:String):String;

3
interface IGamma
{
function doSomething(param:int = 3):void;
}

Igamma
class Gamma implements IGamma
{
public function doSomething(param:int = 4):void {}
}

extends

Shape
Circle Square Shape area()
Circle Square area()

Circle Square area()
class Shape
{
public function area():Number

134

ActionScript

{
return NaN;
}
}
class Circle extends Shape
{
private var radius:Number = 1;
override public function area():Number
{
return ([Link] * (radius * radius));
}
}
class Square extends Shape
{
private var side:Number = 1;
override public function area():Number
{
return (side * side);
}
}
var cir:Circle = new Circle();
trace([Link]()); // 3.141592653589793
var sq:Square = new Square();
trace([Link]()); // 1

Shape (parameter) Circle Shape Circle


(argument)
function draw(shapeToDraw:Shape) {}
var myCircle:Circle = new Circle();
draw(myCircle);

(property) function var const


private (attribute) (property)
Flash Player API Event

Event
Event complete connect

135

Event

public class Event


{
public function get type():String;
public function get bubbles():Boolean;
...
public
public
public
public
...

function
function
function
function

stopPropagation():void {}
stopImmediatePropagation():void {}
preventDefault():void {}
isDefaultPrevented():Boolean {}

Event Event
Event MouseEvent
mouseMove click
MouseEvent

public class MouseEvent extends Event


{
public static const CLICK:String
= "click";
public static const MOUSE_MOVE:String = "mouseMove";
...
public function get stageX():Number {}
public function get stageY():Number {}
...
}

public public
private protected internal
private
ActionScript private
ActionScript 3.0 protected
protected

Java protected ActionScript 3.0 protected


ActionScript 3.0
protected protected

136

ActionScript

internal
internal
internal

AccessControl Base Extender Base


foo Extender Base bar AccessControl
Extender Extender Base
str str public
// [Link] foo
package foo
{
public class Base
{
public var str:String = "hello"; // public
}
}
// [Link] bar
package bar
{
import [Link];
public class Extender extends Base
{
public function getString():String {
return str;
}
}
}
// [Link]
import [Link];
import [Link];
public class AccessControl extends MovieClip
{
public function AccessControl()
{
var myExt:Extender = new Extender();
trace([Link]); // str public
trace([Link]()); // str private internal
}
}
}

137

AccessControl
str private protected
internal
trace([Link]);

// str public

var const
function
getter setter
139 getter setter

final final

private
private override

override

super

super
Base
thanks() Extender Base thanks()
[Link]() super [Link]()

138

ActionScript

package {
import [Link];
public class SuperExample extends MovieClip
{
public function SuperExample()
{
var myExt:Extender = new Extender()
trace([Link]()); // Mahalo nui loa
}
}
}
class Base {
public function thanks():String
{
return "Mahalo";
}
}
class Extender extends Base
{
override public function thanks():String
{
return [Link]() + " nui loa";
}
}

getter setter
getter setter
Flash Player API MovieClip currentLabel getter
package
{
import [Link];
public class OverrideExample extends MovieClip
{
public function OverrideExample()
{
trace(currentLabel)
}
override public function get currentLabel():String
{
var str:String = "Override: ";
str += [Link];
return str;
}
}
}

OverrideExample trace() Override:

null

currentLabel

139

Base Extender
Base Base test

package {
import [Link];
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
trace([Link]); //
}
}
}
class Base {
public static var test:String = "static";
}
class Extender extends Base { }

test
[Link];

Base test
Extender test
Extender
package
{
import [Link];
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
trace([Link]); //
}
}
}

140

ActionScript

class Base
{
public static var test:String = "static";
public var test:String = "instance";
}
class Extender extends Base {}

Base test
Extender Extender test
test
package
{
import [Link];
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
}
}
}
class Base {
public static var test:String = "static";
}
class Extender extends Base
{
public function Extender()
{
trace(test); //
}
}


Extender test
trace()

141

package
{
import [Link];
public class StaticExample extends MovieClip
{
public function StaticExample()
{
var myExt:Extender = new Extender();
}
}
}
class Base
{
public static var test:String = "static";
}
class Extender extends Base
{
public var test:String = "instance";
public function Extender()
{
trace(test); //
}
}

ActionScript OOP ActionScript 3.0


ActionScript (AVM2)
ActionScript (AVM1) Flash Player

ActionScript OOP
ActionScript 3.0 ActionScript ActionScript
ActionScript Flash
ActionScript

142

ActionScript

ActionScript 1.0
ActionScript 1.0 Flash Player 6
ActionScript ActionScript

ActionScript class
Java C++ class
ActionScript 1.0


ActionScript 1.0 ActionScript

Shape visible
true
//
function Shape() {}
// visible
[Link] = true;

new Shape
myShape = new Shape();

Shape() Shape
Shape

Shape

Shape

//
function Circle(id, radius)
{
[Link] = id;
[Link] = radius;
}

new Shape Circle


Object [Link] Object
Circle Shape Object [Link]
Shape
// Circle Shape
[Link] = new Shape();

143

Shape Circle

[Link]

[Link]

[Link]

Object Object [Link]


ActionScript 1.0
Shape [Link]
Object Circle
Shape [Link] Shape
Circle Circle
// Circle
myCircle = new Circle();

visible Shape visible


myCircle Shape
true
trace([Link]); // true

Flash Player myCircle visible


Flash Player myCircle visible
Flash Player [Link]
visible Flash Player [Link]
visible

ActionScript 3.0

ActionScript 2.0
ActionScript 2.0 class extends public private
Java C++
ActionScript 1.0 ActionScript 2.0
ActionScript 2.0

144

ActionScript

ActionScript 2.0

//
class Shape
{
var visible:Boolean = true;
}

ActionScript 2.0
visible extends
extends ActionScript 1.0

//
class Circle extends Shape
{
var id:Number;
var radius:Number;
function Circle(id, radius)
{
[Link] = id;
[Link] = radius;
}
}

id radius

ActionScript 2.0

ActionScript 3.0
Java C++
ActionScript

ActionScript
ActionScript ActionScript 3.0

ActionScript

145

class A {} A

[Link]

[Link]

CA

A
A (CA) traits (TA)
traits (TCA)
C (PA) constructor

traits
traits ActionScript 3.0
ActionScript Flash Player
ActionScript 3.0
traits
traits traits
AVM2 AVM2

traits ActionScript
dynamic
traits
ActionScript 2.0 100 ActionScript 3.0
20

146

traits ActionScript

ActionScript

ActionScript prototype
ActionScript 143
ActionScript 1.0
prototype

ActionScript prototype prototype


prototype

ActionScript ActionScript 3.0


traits
class extends
override

prototype

dynamic

Object Object toString()


Object

valueOf()


public dynamic class Object
{
[Link] = function()
{
//
};
[Link] = function()
{
//
};
}

Object
toString()
[Link] = function()
{
//
};

147


override Object valueOf()
valueOf()
Foo Object Foo valueOf()
Object extends
dynamic class Foo
{
[Link] = function()
{
return "Instance of Foo";
};
}

Foo valueOf()
[Link] = function()
{
return "Instance of Foo";
};

valueOf() Foo
valueOf() Foo
override valueOf() Foo
class Foo
{
function valueOf():String
{
return "Instance of Foo";
}
}

AS3

ECMAScript 4

Flash Player API


constvar function

ActionScript 3.0
ECMAScript
AS3 Flash Player API

148

ActionScript

AS3 AS3

AS3 AS3

AS3 AS3
AS3 [Link]()
var nums:Array = new Array(1, 2, 3);
nums.AS3::pop();
trace(nums); // 1,2

use namespace AS3


use namespace pop() push() AS3
use namespace AS3;
var nums:Array = new Array(1, 2, 3);
[Link]();
[Link](5);
trace(nums) // 1,2,5

ActionScript 3.0 AS3


-as3 AS3 -es es
ECMAScript AS3 -as3 true
-es false
Adobe Flex Builder 2 Adobe Flash CS3 Professional -as3 = true
-es = false
AS3
AS3 AS3
override AS3
AS3 override

GeometricShapes
GeometricShapes ActionScript 3.0

override

GeometricShapes

149

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/GeometricShapes GeometricShapes

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/
geometricshapes/[Link]

GeometricShapes

com/example/programmingas3/
geometricshapes/[Link]

GeometricShapes

com/example/programmingas3/
geometricshapes/[Link]

com/example/programmingas3/
geometricshapes/[Link]

com/example/programmingas3/
geometricshapes/[Link]

RegularPolygon

com/example/programmingas3/
geometricshapes/[Link]

RegularPolygon

com/example/programmingas3/
geometricshapes/
[Link]

GeometricShapes
GeometricShapes

363
SpriteArranger SpriteArranger
GeometricShapes

150

ActionScript

(UML)
GeometricShapes
<< interface >>
IGeometricShape
+getArea (): Number
+describe (): Strin

Circle
+diameter:Number
+Circle () : Circle
+getArea () : Number
+describe () : String
+getCircumference () : Number

<< interface >>


IPolygon
+getPerimeter (): Number
+getSumOfAngles (): Number

RegularPolygon
+numSides : int
+sideLength : Number
+RegularPolygon (): RegularPolygon
+getSumOfAngles (): Number
+getPerimeter (): Number
+getArea (): Number
+describe (): String

EquilateralTriangle
+EquilateralTriangle (): EquilateralTriangle
+getArea (): Number
+describe (): String

Square
+Square (): Square
+getArea (): Number
+describe (): String

GeometricShapes GeometricShapes
IGeometricShape

package [Link]
{
public interface IGeometricShape
{
function getArea():Number;
function describe():String;
}
}

getArea() describe()

GeometricShapes

151

IPolygon IPolygon

package [Link]
{
public interface IPolygon extends IGeometricShape
{
function getPerimeter():Number;
function getSumOfAngles():Number;
}
}

getPerimeter() getSumOfAngles()

IPolygon IGeometricShape IPolygon


IGeometricShape IPolygon

Circle
package [Link]
{
public class Circle implements IGeometricShape
{
public var diameter:Number;
public function Circle(diam:Number = 100):void
{
[Link] = diam;
}
public function getArea():Number
{
// The formula is Pi * radius * radius.
var radius:Number = diameter / 2;
return [Link] * radius * radius;
}
public function getCircumference():Number
{
// The formula is Pi * diameter.
return [Link] * diameter;
}

152

ActionScript

public function describe():String


{
var desc:String = "This shape is a Circle.\n";
desc += "Its diameter is " + diameter + " pixels.\n";
desc += "Its area is " + getArea() + ".\n";
desc += "Its circumference is " + getCircumference() + ".\n";
return desc;
}
}
}

Circle IGeometricShape getArea() describe()


getCircumference() Circle
Circle diameter

RegularPolygon Square EquilateralTriangle


RegularPolygon
package [Link]
{
public class RegularPolygon implements IPolygon
{
public var numSides:int;
public var sideLength:Number;
public function RegularPolygon(len:Number = 100, sides:int = 3):void
{
[Link] = len;
[Link] = sides;
}
public function getArea():Number
{
// This method should be overridden in subclasses.
return 0;
}
public function getPerimeter():Number
{
return sideLength * numSides;
}
public function getSumOfAngles():Number
{
if (numSides >= 3)
{
return ((numSides - 2) * 180);

GeometricShapes

153

}
else
{
return 0;
}
}
public function describe():String
{
var desc:String = "Each side is " + sideLength + " pixels long.\n";
desc += "Its area is " + getArea() + " pixels square.\n";
desc += "Its perimeter is " + getPerimeter() + " pixels long.\n";
desc += "The sum of all interior angles in this shape is " +
getSumOfAngles() + " degrees.\n";
return desc;
}
}
}

RegularPolygon sideLength
numSides

RegularPolygon IPolygon IPolygon


getPerimeter() getSumOfAngles()
getArea()
0
RegularPolygon getArea()

EquilateralTriangle getArea()
package [Link]
{
public class EquilateralTriangle extends RegularPolygon
{
public function EquilateralTriangle(len:Number = 100):void
{
super(len, 3);
}
public override function getArea():Number
{
// The formula is ((sideLength squared) * (square root of 3)) / 4.
return ( ([Link] * [Link]) * [Link](3) ) / 4;
}
public override function describe():String
{
/* starts with the name of the shape, then delegates the rest
of the description work to the RegularPolygon superclass */
var desc:String = "This shape is an equilateral Triangle.\n";

154

ActionScript

desc += [Link]();
return desc;
}
}
}
override [Link]() RegularPolygon
getArea() [Link]()
[Link]()

EquilateralTriangle getPerimeter()
[Link]() RegularPolygon
getPerimeter()
EquilateralTriangle() super()
RegularPolygon()
EquilateralTriangle() RegularPolygon()
RegularPolygon() numSidesEquilateralTriangle()

super(len, 3) len 3 3
describe() super() describe()

RegularPolygon [Link]() desc


[Link]() [Link]()
desc
Square EquilateralTriangle
getArea() describe()

IGeometricShape
IGeometricShape Circle Square
describe()

var myShape:IGeometricShape = new Circle(100);


trace([Link]());

[Link]() [Link]()
IGeometricShape Circle

GeometricShapes

155

GeometricShapes

GeometricShapeFactory createShape()
package [Link]
{
public class GeometricShapeFactory
{
public static var currentShape:IGeometricShape;
public static function createShape(shapeName:String,
len:Number):IGeometricShape
{
switch (shapeName)
{
case "Triangle":
return new EquilateralTriangle(len);
case "Square":
return new Square(len);
case "Circle":
return new Circle(len);
}
return null;
}
public static function describeShape(shapeType:String,
shapeSize:Number):String
{
[Link] =
[Link](shapeType, shapeSize);
return [Link]();
}
}
}
createShape()

IGeometricShape
describeShape()
Circle
[Link](Circle, 100);

describeShape() createShape()
Circle currentShape IGeometricShape
currentShape describe()
[Link]()

156

ActionScript

Pentagon
RegularPolygon getArea() describe()
Pentagon Pentagon
RegularPolygon getPerimeter() getSumOfAngles()
IGeometricShape Pentagon
IGeometricShape GeometricShapeFactory

Pentagon Geometric

Shapes

GeometricShapes

157

158

ActionScript

ActionScript 3.0

Date [Link] Timer

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

159

ActionScript

ActionScript Date Date

ActionScript Timer

Date

UTC (UTC time)


UTC

Date
trace() 53

160


ActionScript 3.0 Date Date
(UTC)
UTC (GMT)

Date
Date
Date
Date()
Date
var now:Date = new Date();

Date() 1970 1 1
Date 1970
1 1 UTC Date
UTC
Date UTC
1970 1 1 UTC Date
var millisecondsPerDay:int = 1000 * 60 * 60 * 24;
// 1970 1 1 Date
var startTime:Date = new Date(millisecondsPerDay);

Date()
Date
UTC 2000 1 1
Date
var millenium:Date = new Date(2000, 0, 1, 0, 0, 0, 0);

Date()
Date Date()
try..catch Date()
ActionScript 3.0
Date
var nextDay:Date = new Date(Mon May 1 2006 [Link] AM);

Date()
Date

161


Date Date
Date

fullYear

month

0 11
date 1 31
day 0
hours 0 23

minutes

seconds

milliseconds

Date
Date

month

getMonth()

monthUTC

getMonthUTC()

milliseconds
1000 1 milliseconds 0

999

Date 1970 1 1 (UTC)


1970 1 1
(UTC) Date

getTime() setTime()

Date
Date

public static const millisecondsPerMinute:int = 1000 * 60;


public static const millisecondsPerHour:int = 1000 * 60 * 60;
public static const millisecondsPerDay:int = 1000 * 60 * 60 * 24;

162

getTime() setTime()

var oneHourFromNow:Date = new Date();


[Link]([Link]() + millisecondsPerHour);

30

Date

//
var invoiceDate:Date = new Date();

// 30
var dueDate:Date = new Date([Link]() + (30 * millisecondsPerDay));

millisecondsPerDay 30
invoiceDate dueDate

30

getTimezoneOffset() Date UTC

Date

UTC

// Date
var nextDay:Date = new Date("Mon May 1 2006 [Link] AM");
// Date UTC
var offsetMilliseconds:Number = [Link]() * 60 * 1000;
[Link]([Link]() + offsetMilliseconds);

163


Adobe Flash CS3 Professional
ActionScript

for do..while

ActionScript 3.0 Timer ActionScript


Timer

3.0

Timer
ActionScript 3.0 Timer ([Link])

Timer

60 Timer
var oneMinuteTimer:Timer = new Timer(1000, 60);

Timer TimerEvent TimerEvent


timer [Link] TimerEvent
Event
Timer
timerComplete TimerEvent.TIMER_COMPLETE
Timer
package
{
import [Link];
import [Link];
import [Link];
public class ShortTimer extends Sprite
{
public function ShortTimer()
{

164

// Timer
var minuteTimer:Timer = new Timer(1000, 5);
//
[Link]([Link], onTick);
[Link](TimerEvent.TIMER_COMPLETE,
onTimerComplete);
//
[Link]();
}
public function onTick(event:TimerEvent):void
{
//
// Timer
trace("tick" + [Link]);
}
public function onTimerComplete(event:TimerEvent):void
{
trace("Time's Up!");
}
}
}

ShortTimer Timer
timerComplete

onTick()
onTick() onTimerComplete()

tick 1
tick 2
tick 3
tick 4
tick 5
Time's Up!

165

[Link]
ActionScript 3.0 ActionScript 2.0
[Link] ActionScript 2.0

clearInterval(id:uint):void

setInterval()

clearTimeout(id:uint):void

setTimeout()

getTimer():int

Adobe Flash Player

setInterval(closure:Function,
delay:Number, ... arguments):uint

setTimeout(closure:Function,
delay:Number, ... arguments):uint

ActionScript 3.0 Adobe


ActionScript 3.0 Timer

Timer

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/SimpleClock SimpleClock

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/
simpleclock/[Link]

com/example/programmingas3/
simpleclock/[Link]

166

SimpleClock

SimpleClock SimpleClock
AnalogClockFace

SimpleClock Flash SimpleClock


Sprite
public class SimpleClock extends UIComponent
{
/**
*
*/
private var face:AnalogClockFace;
/**
* Timer
*/
private var ticker:Timer;

AnalogClockFace
Timer

face

ticker

SimpleClock initClock()
Timer

SimpleClock
/**
* SimpleClock
*/
public function initClock(faceSize:Number = 200)
{
//
face = new AnalogClockFace([Link](20, faceSize));
[Link]();
addChild(face);
//
[Link]();

initClock() faceSize

200

167

DisplayObject addChild()
[Link]()

initClock()
// Timer
ticker = new Timer(1000);
// onTick() Timer
[Link]([Link], onTick);
//
[Link]();

1000 Timer
Timer() repeatCount Timer
[Link]() timer
public function onTick(event:TimerEvent):void
{
//
[Link]();
}
[Link]()

AnalogClockFace AnalogClockFace

Shape
SimpleClock [Link]()

/**
*
*/
public override function draw():void
{
//
currentTime = new Date();
showTime(currentTime);
}

168


showTime()
/**
* Date/Time
*/
public function showTime(time:Date):void
{
//
var seconds:uint = [Link]();
var minutes:uint = [Link]();
var hours:uint = [Link]();
// 6
[Link] = 180 + (seconds * 6);
[Link] = 180 + (minutes * 6);
// 30
// 29.5 (59 * 0.5)
//
[Link] = 180 + (hours * 30) + (minutes * 0.5);
}

60 6 (360/60)

30 (360/12) 30 60

169

170

String
TextField StaticText XML ContextMenu
FileReference
ActionScript 3.0 ASCII Unicode

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .177
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .177
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
ASCII . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

171

String

var albumName:String = "Three for the money";

ActionScript

"Hello"
"555-7649"
"[Link]

ActionScript ActionScript String


String ActionScript

String

172

ASCII ASCII

26

(Character)

(Concatenation)

(Empty string) ""


String String String

(String)

String literal literal string

(Substring)

Unicode Unicode

trace() 53

ActionScript 3.0 String ActionScript


ASCII Unicode
(") (')
var str1:String = "hello";
var str2:String = 'hello';

new
var str1:String = new String("hello");
var str2:String = new String(str1);
var str3:String = new String();
// str3 == ""

173


var str1:String = "hello";
var str2:String = new String("hello");

(') (') (\)


(") (")
(\)
var str1:String = "That's \"A-OK\"";
var str2:String = 'That\'s "A-OK"';

var str1:String = "ActionScript <span class='heavy'>3.0</span>";


var str2:String = '<item id="155">banana</item>';

ActionScript (') ( )
ActionScript

(\)

\b

\f

\n

\r

\t

\unnnn

Unicode nnnn \u263a

\xnn

ASCII nn

\'

\"

\\

174

length
length
var str:String = "Adobe";
trace([Link]);

// 5

null 0
var str1:String = new String();
trace([Link]);
// 0
str2:String = '';
trace([Link]);

// 0

0
y 0 w 5
"yellow"

charAt() charCodeAt()
var str:String = "hello world!";
for (var:i = 0; i < [Link]; i++)
{
trace([Link](i), "-", [Link](i));
}

h
e
l
l
o
w
o
r
l
d
!

104
101
108
108
111
32
119
111
114
108
100
33

fromCharCode()
var myStr:String =
[Link](104,101,108,108,111,32,119,111,114,108,100,33);
// myStr hello world!

175


< <= != == => >
if while
var str1:String = "Apple";
var str2:String = "apple";
if (str1 < str2)
{
trace("A < a, B < b, C < c, ...");
}

ActionScript

trace("A" < "B"); // true


trace("A" < "a"); // true
trace("Ab" < "az"); // true
trace("abc" < "abza"); // true

== !=

var str1:String = "1";


var str1b:String = "1";
var str2:String = "2";
trace(str1 == str1b); // true
trace(str1 == str2); // false
var total:uint = 1;
trace(str1 == total); // true

toString()

var n:Number = 99.47;


var str:String = [Link]();
// str == "99.47"

+ String toString()

String() toString()

176

var str1:String = "green";


var str2:String = "ish";
var str3:String = str1 + str2; // str3 == "greenish"

+=
var str:String = "green";
str += "ish"; // str == "greenish"

String concat()
var str1:String = "Bonjour";
var str2:String = "from";
var str3:String = "Paris";
var str4:String = [Link](" ", str2, " ", str3);
// str4 == "Bonjour from Paris"

+ += String
ActionScript String
var str:String = "Area = ";
var area:Number = [Link] * [Link](3, 2);
str = str + area; // str == "Area = 28.274333882308138"

+
trace("Total: $" + 4.55 + 1.45); // Total: $4.551.45
trace("Total: $" + (4.55 + 1.45)); // Total: $6

"abc" """a""ab"
"abc" "b" "bc" "c" ActionScript
ActionScript
AB C
/ABC\d/

ActionScript

243 9

177


substr() substring()

substr() substring()

var str:String = "Hello from Paris, Texas!!!";


trace([Link](11,15)); // Paris, Texas!!!
trace([Link](11,15)); // Pari
slice() substring()
slice()

var str:String = "Hello from Paris, Texas!!!";


trace([Link](11,15)); // Pari
trace([Link](-3,-1)); // !!
trace([Link](-3,26)); // !!!
trace([Link](-3,[Link])); // !!!
trace([Link](-8,-3)); // Texas

slice()

indexOf() lastIndexOf()
var str:String = "The moon, the stars, the sea, the land";
trace([Link]("the")); // 10

indexOf()

var str:String = "The moon, the stars, the sea, the land"
trace([Link]("the", 11)); // 21
lastIndexOf()
var str:String = "The moon, the stars, the sea, the land"
trace([Link]("the")); // 30

lastIndexOf()

var str:String = "The moon, the stars, the sea, the land"
trace([Link]("the", 29)); // 21

178


split()

(&)
var queryStr:String = "first=joe&last=cheng&title=manager&StartDate=3/6/65";
var params:Array = [Link]("&", 2); // params ==
["first=joe","last=cheng"]
split()

var str:String = "Give me\t5."


var a:Array = [Link](/\s+/); // a == ["Give","me","5."]

243 9 ActionScript

3.0

String

match() search()

replace()

243 9

search()
var str:String = "The more the merrier.";
//
trace([Link]("the")); // 9

var pattern:RegExp = /the/i;


var str:String = "The more the merrier.";
trace([Link](pattern)); // 0

0 0
i

trace()

search() g

179


var pattern:RegExp = /"[^"]*"/;
var str:String = "The \"more\" the merrier.";
trace([Link](pattern)); // 4
str = "The \"more the merrier.";
trace([Link](pattern)); // -1
//
match()

match()
var str:String = "bob@[Link], omar@[Link]";
var pattern:RegExp = /\w*@\w*\.[org|com]+/g;
var results:Array = [Link](pattern);
results
["bob@[Link]","omar@[Link]"]

243 9

replace()

var str:String = "She sells seashells by the seashore.";


var pattern:RegExp = /sh/gi;
trace([Link](pattern, "sch"));
//sche sells seaschells by the seaschore.

i (ignoreCase)
g (global)
243 9
$ $

$$

$&

$`

(`)
(') ()

$'

()

180

$n

n n 1-9 $n

$nn

nn nn (01-99)
nn

$2 $1

var str:String = "flip-flop";


var pattern:RegExp = /(\w+)-(\w+)/g;
trace([Link](pattern, "$2-$1")); // flop-flip

replace()
var str:String = "Now only $9.95!";
var price:RegExp = /\$([\d,]+.\d+)+/i;
trace([Link](price, usdToEuro));
function usdToEuro(matchedSubstring:String,
capturedMatch1:String,
index:int,
str:String):String
{
var usd:String = capturedMatch1;
usd = [Link](",", "");
var exchangeRate:Number = 0.853690;
var euro:Number = usd * exchangeRate;
const euroSymbol:String = [Link](8364);
return [Link](2) + " " + euroSymbol;
}

replace()

[Link] - 3

181


toLowerCase() toUpperCase()

var str:String = "Dr. Bob Roberts, #9."


trace([Link]()); // dr. bob roberts, #9.
trace([Link]()); // DR. BOB ROBERTS, #9.

str = [Link]();

a-z A-Z
var str:String = "Jos Bara";
trace([Link](), [Link]()); // JOS BARA jos bara

ASCII
ASCII

ActionScript 3.0 String

String split()

split() substring() substr()

getCharAt()

ASCII

182

ASCII

ASCII Courier
New ASCII

ASCII

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/AsciiArt ASCIIArt

[Link]

Flash (FLA) Flex (MXML)

[Link]
com/example/programmingas3/asciiArt/
[Link]

com/example/programmingas3/asciiArt/
[Link]

parseBitmapData()

com/example/programmingas3/asciiArt/
[Link]

com/example/programmingas3/asciiArt/
[Link]

ASCII
URL

ASCII

183

image/

txt/[Link]

SWF
URL
txt/[Link]

FILENAMETITLEWHITE_THRESHHOLDBLACK_THRESHHOLD
[Link], apple, orange, and bananad810
[Link] picture of a bananaC820
Orange.jpgorangeFF20
[Link] of an apple6E10

AsciiArtBuilder
AsciiArtBuilder parseImageInfo()

var lines:Array = _imageInfoLoader.[Link]("\n");


var numLines:uint = [Link];
for (var i:uint = 1; i < numLines; i++)
{
var imageInfoRaw:String = lines[i];
...
if ([Link] > 0)
{
//
var imageInfo:ImageInfo = new ImageInfo();
// (\t)
//
var imageProperties:Array = [Link]("\t");
[Link] = imageProperties[0];

184

[Link] = normalizeTitle(imageProperties[1]);
[Link] = parseInt(imageProperties[2], 16);
[Link] = parseInt(imageProperties[3], 16);
[Link](imageInfo);
}
}

String _imageInfoLoader.data
split() (\n) String Array (lines)

split()
imageProperties Array split()
(\t)

String

[Link] = normalizeTitle(imageProperties[1]);

ImageInfo
normalizeTitle()
private function normalizeTitle(title:String):String
{
var words:Array = [Link](" ");
var len:uint = [Link];
for (var i:uint; i < len; i++)
{
words[i] = capitalizeFirstLetter(words[i]);
}
return [Link](" ");
}

split()
capitalizeFirstLetter() Array join()

ASCII

185

capitalizeFirstLetter()

/**
*
*
*/
private function capitalizeFirstLetter(word:String):String
{
switch (word)
{
case "and":
case "the":
case "in":
case "an":
case "or":
case "at":
case "of":
case "a":
//
break;
default:
//
var firstLetter:String = [Link](0, 1);
firstLetter = [Link]();
var otherLetters:String = [Link](1);
word = firstLetter + otherLetters;
}
return word;
}


andthein an orat of a
switch
switch
1.

substr(0, 1) 0
0
1

2. toUpperCase()
3. substring(1)

1
substring()

4. firstLetter + otherLetters

186

ASCII
BitmapToAsciiConverter ASCII
parseBitmapData()
var result:String = "";
//
for (var y:uint = 0; y < _data.height; y += verticalResolution)
{
//
for (var x:uint = 0; x < _data.width; x += horizontalResolution)
{
...
// 0-255
// 0-64
//
index = [Link](grayVal / 4);
result += [Link](index);
}
result += "\n";
}
return result;

result String ASCII


0-255 4
0-63 index 0-63
ASCII 64
BitmapToAsciiConverter String
//
//
// 0 =
private static const palette:String =
"@#$%&8BMW*mwqpdbkhaoQ0OZXYUJCLtfjzxnuvcr[]{}1()|/?Il!i><+_~-;,. ";

index ASCII
charAt() palette (+=)
result result

ASCII

187

188

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
PlayList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210

Song

ActionScript

189


ActionScript addSongsToPlaylist()

addSongsToPlaylist()
Song addSongsToPlaylist()

ActionScript
Array



ActionScript 3.0 Dictionary

(Array)

(Associative array)

(Dictionary)

(Element)

(Index)

190

(Indexed array)

(Key)

(Multidimensional array)

trace()
1.

Flash

2.
3.
4. >

trace()
53

0 1
Array

// Array
var myArray:Array = new Array();
[Link]("one");
[Link]("two");
[Link]("three");
trace(myArray); // one,two,three
//
var myArray:Array = ["one", "two", "three"];
trace(myArray); // one,two,three

Array

32 232-1
4,294,967,295

191

ActionScript 3.0

Array

Array

Array
Array length
Array
var names:Array = new Array();
trace([Link]); // 0

Array
undefined 0 4,294,967,295
Array
var names:Array = new Array(3);
trace([Link]); // 3
trace(names[0]); // undefined
trace(names[1]); // undefined
trace(names[2]); // undefined

Array
var names:Array = new Array("John", "Jane", "David");
trace([Link]); // 3
trace(names[0]); // John
trace(names[1]); // Jane
trace(names[2]); // David

var names:Array = ["John", "Jane", "David"];

192


Array push()unshift() splice()push()
push()
unshift()
0 splice()
planets
push() Mars
unshift() Mercury splice() Mercury
Mars Venus Earth splice() 1
1 splice() 0
splice() Venus Earth
var planets:Array = new Array();
[Link]("Mars");
// Mars
[Link]("Mercury"); // Mercury,Mars
[Link](1, 0, "Venus", "Earth");
trace(planets);
// Mercury,Venus,Earth,Mars
push() unshift()
splice() splice()
splice()
splice()

Array pop() shift() splice() pop()


shift()
0 splice()

oceans

splice() Aral Superior Atlantic Indian


splice() 2 2
2 Atlantic Indian
2

193

pop() Huron shift()


Victoria
var oceans:Array = ["Victoria", "Pacific", "Aral", "Superior", "Indian",
"Huron"];
[Link](2, 2, "Arctic", "Atlantic"); // Aral Superior
[Link]();
// Huron
[Link](); // Victoria
trace(oceans); // Pacific,Arctic,Atlantic,Indian
pop() shift()
Object splice() oceans
splice()
var lakes:Array = [Link](2, 2, "Arctic", "Atlantic");
trace(lakes); // Aral,Superior

delete delete
undefined oceans
delete 5
var oceans:Array = ["Arctic", "Pacific", "Victoria", "Indian", "Atlantic"];
delete oceans[2];
trace(oceans);
// Arctic,Pacific,,Indian,Atlantic
trace(oceans[2]);
// undefined
trace([Link]); // 5

length length
length 1
oceans length

var oceans:Array = ["Arctic", "Pacific", "Victoria", "Aral", "Superior"];


[Link] = 2;
trace(oceans); // Arctic,Pacific

reverse() sort() sortOn()


reverse()
sort()

sortOn()

194

reverse()
oceans
var oceans:Array = ["Arctic", "Atlantic", "Indian", "Pacific"];
[Link]();
trace(oceans); // Pacific,Indian,Atlantic,Arctic
sort()

D b

10
3 "3" "1"

A B

sort() options
options Array

[Link]

[Link]

B A

[Link]

[Link]

3 10

poets

var poets:Array = ["Blake", "cummings", "Angelou", "Dante"];


[Link](); //
trace(poets); // Angelou,Blake,Dante,cummings
[Link]([Link]);
trace(poets); // Angelou,Blake,cummings,Dante
[Link]([Link]);
trace(poets); // cummings,Dante,Blake,Angelou
[Link]([Link] | [Link]); //
trace(poets); // Dante,cummings,Blake,Angelou

195

sort()

[Link]()
var names:Array = new Array("John Q. Smith", "Jane Doe", "Mike Jones");
function orderLastName(a, b):int
{
var lastName:RegExp = /\b\S+$/;
var name1 = [Link](lastName);
var name2 = [Link](lastName);
if (name1 < name2)
{
return -1;
}
else if (name1 > name2)
{
return 1;
}
else
{
return 0;
}
}
trace(names); // John Q. Smith,Jane Doe,Mike Jones
[Link](orderLastName);
trace(names); // Jane Doe,Mike Jones,John Q. Smith

orderLastName()
names sort() orderLastName
a b

-1 a b

1 b a

sortOn()
sortOn()

poets

var poets:Array = new Array();


[Link]({name:"Angelou", born:"1928"});
[Link]({name:"Blake", born:"1757"});
[Link]({name:"cummings", born:"1894"});
[Link]({name:"Dante", born:"1265"});
[Link]({name:"Wang", born:"701"});

196

sortOn() born sortOn()


fieldName options fieldName
"born" [Link] sortOn() [Link]

[Link]("born", [Link]);
for (var i:int = 0; i < [Link]; ++i)
{
trace(poets[i].name, poets[i].born);
}
/*
Wang 701
Dante 1265
Blake 1757
cummings 1894
Angelou 1928
*/

sort() sortOn()
[Link] options

poets
options [Link]

indices indices
poets
var indices:Array;
indices = [Link]("born", [Link] | [Link]);
for (var i:int = 0; i < [Link]; ++i)
{
var index:int = indices[i];
trace(poets[index].name, poets[index].born);
}
/*
Wang 701
Dante 1265
Blake 1757
cummings 1894
Angelou 1928
*/

197


Array concat()join()slice() toString()
concat() slice() join() toString()
concat()
slice() startIndex endIndex
startIndex
endIndex endIndex
concat() slice()
var array1:Array = ["alpha", "beta"];
var array2:Array = [Link]("gamma", "delta");
trace(array2); // alpha,beta,gamma,delta
var array3:Array = [Link](array2);
trace(array3); // alpha,beta,alpha,beta,gamma,delta
var array4:Array = [Link](2,5);
trace(array4); // alpha,beta,gamma

join() toString() join()



toString() join() delimiter

rivers join() toString()


toString() (riverCSV) join()
+
var rivers:Array = ["Nile", "Amazon", "Yangtze", "Mississippi"];
var riverCSV:String = [Link]();
trace(riverCSV); // Nile,Amazon,Yangtze,Mississippi
var riverPSV:String = [Link]("+");
trace(riverPSV); // Nile+Amazon+Yangtze+Mississippi

join()

var nested:Array = ["b","c","d"];


var letters:Array = ["a",nested,"e"];
var joined:String = [Link]("+");
trace(joined); // a+b,c,d+e

198



Object

ActionScript 3.0 [Link] Dictionary


Object
String
Dictionary

ActionScript 3.0 Object


Object

monitorInfo

var monitorInfo:Object = {type:"Flat Panel", resolution:"1600 x 1200"};


trace(monitorInfo["type"], monitorInfo["resolution"]);
// Flat Panel 1600 x 1200

Object
var monitorInfo:Object = new Object();

Object ([]) (.)


monitorArray
monitorInfo["aspect ratio"] = "16:10"; //
[Link] = "16.7 million";
trace(monitorInfo["aspect ratio"], [Link]);
// 16:10 16.7 million

aspect ratio

199

Array ([]) (.)


Array
Array monitorInfo
type resolution
var monitorInfo:Array = new Array();
monitorInfo["type"] = "Flat Panel";
monitorInfo["resolution"] = "1600 x 1200";
trace(monitorInfo["type"], monitorInfo["resolution"]);
// Flat Panel 1600 x 1200

Array Array Array


Array [Link] Array

Dictionary
Sprite
Sprite Dictionary Sprite
Dictionary Sprite
GroupA GroupBGroupA GroupB Object
([])
import [Link];
import [Link];
var groupMap:Dictionary = new Dictionary();
//
var spr1:Sprite = new Sprite();
var spr2:Sprite = new Sprite();
var spr3:Sprite = new Sprite();
//
var groupA:Object = new Object();
var groupB:Object = new Object();
// -
groupMap[spr1] = groupA;
groupMap[spr2] = groupB;
groupMap[spr3] = groupB;
if (groupMap[spr1] == groupA)
{
trace("spr1 is in groupA");
}

200

if (groupMap[spr2] == groupB)
{
trace("spr2 is in groupB");
}
if (groupMap[spr3] == groupB)
{
trace("spr3 is in groupB");
}

for..in for each..in Dictionary for..in


for each..in

for..in Dictionary
([]) Dictionary groupMap
for..in Dictionary
for (var key:Object in groupMap)
{
trace(key, groupMap[key]);
}
/*
[object Sprite] [object Object]
[object Sprite] [object Object]
[object Sprite] [object Object]
*/

for each..in Dictionary groupMap


for each..in Dictionary
for each (var item:Object in groupMap)
{
trace(item);
}
/*
[object Object]
[object Object]
[object Object]
*/

201


Adobe Flash Player

myObject
var myObject:Object = new Object();

myObject
null

myObject Dictionary
myObject myMap
import [Link];
var myObject:Object = new Object();
var myMap:Dictionary = new Dictionary();
myMap[myObject] = "foo";

myObject
myObject myMap myObject
myObject = null;
delete myMap[myObject];

Dictionary useWeakReference

myMap myObject
import [Link];
var myObject:Object = new Object();
var myMap:Dictionary = new Dictionary(true);
myMap[myObject] = "foo";
myObject = null; //

var tasks:Array = ["wash dishes", "take out trash"];

tasks

202

masterTaskList Array
0 6
masterTaskList

var masterTaskList:Array = new Array();


masterTaskList[0] = ["wash dishes", "take out trash"];
masterTaskList[1] = ["wash dishes", "pay bills"];
masterTaskList[2] = ["wash dishes", "dentist", "wash dog"];
masterTaskList[3] = ["wash dishes"];
masterTaskList[4] = ["wash dishes", "clean house"];
masterTaskList[5] = ["wash dishes", "wash car", "pay rent"];
masterTaskList[6] = ["mow lawn", "fix chair"];

2 1
trace(masterTaskList[2][1]); // dentist

6
0
trace(masterTaskList[6][0]); // mow lawn

var masterTaskList:Object = new Object();


masterTaskList["Monday"] = ["wash dishes", "take out trash"];
masterTaskList["Tuesday"] = ["wash dishes", "pay bills"];
masterTaskList["Wednesday"] = ["wash dishes", "dentist", "wash dog"];
masterTaskList["Thursday"] = ["wash dishes"];
masterTaskList["Friday"] = ["wash dishes", "clean house"];
masterTaskList["Saturday"] = ["wash dishes", "wash car", "pay rent"];
masterTaskList["Sunday"] = ["mow lawn", "fix chair"];

203


trace([Link][1]); // dentist
trace([Link][0]);
// mow lawn

for..in
masterTaskList

for (var day:String in masterTaskList)


{
trace(day + ": " + masterTaskList[day])
}
/* output:
Sunday: mow lawn,fix chair
Wednesday: wash dishes,dentist,wash dog
Friday: wash dishes,clean house
Thursday: wash dishes
Monday: wash dishes,take out trash
Saturday: wash dishes,wash car,pay rent
Tuesday: wash dishes,pay bills
*/

Array concat() slice()


Array
clone() Java
ByteArray

import [Link];
function clone(source:Object):*
{
var myBA:ByteArray = new ByteArray();
[Link](source);
[Link] = 0;
return([Link]());
}

204


Array
Array Array
Array
ActionScript
Array TypedArray Array
TypedArray
Array
TypedArray

extends Array Array Array


dynamic
TypedArray

public dynamic class TypedArray extends Array


{
private const dataType:Class;
public function TypedArray(...args) {}
AS3 override function concat(...args):Array {}
AS3 override function push(...args):uint {}
AS3 override function splice(...args) {}
AS3 override function unshift(...args):uint {}
}

205

-as3 true -es false


AS3 public Adobe Flex
Builder 2 Adobe Flash CS3 Professional 148
AS3

TypedArray
-es true
override public AS3 [Link]
super

TypedArray

Array 1
[Link]()
[Link]()

TypedArray Array
Array Array
public dynamic class Array
{
public function Array(...args)
{
var n:uint = [Link]
if (n == 1 && (args[0] is Number))
{
var dlen:Number = args[0];
var ulen:uint = dlen;
if (ulen != dlen)
{
throw new RangeError("Array index is not a 32-bit unsigned integer
("+dlen+")");
}
length = ulen;
}
else
{
length = n;
for (var i:int=0; i < n; i++)
{
this[i] = args[i]
}
}
}
}

206

TypedArray Array
Class
dataType else
for length length for
push()
TypedArray
public dynamic class TypedArray extends Array
{
private var dataType:Class;
public function TypedArray(typeParam:Class, ...args)
{
dataType = typeParam;
var n:uint = [Link]
if (n == 1 && (args[0] is Number))
{
var dlen:Number = args[0];
var ulen:uint = dlen
if (ulen != dlen)
{
throw new RangeError("Array index is not a 32-bit unsigned integer
("+dlen+")")
}
length = ulen;
}
else
{
for (var i:int=0; i < n; i++)
{
// push()
[Link](args[i])
}
length = [Link];
}
}
}

207

TypedArray
TypedArray

push() for..in
splice() args for..in
args dataType args push()

AS3 override function push(...args):uint


{
for (var i:* in args)
{
if (!(args[i] is dataType))
{
[Link](i,1);
}
}
return ([Link](this, args));
}
concat() passArgs

TypedArray
push() for..in args
push() passArgs TypedArray
push() TypedArray concat()

AS3 override function concat(...args):Array


{
var passArgs:TypedArray = new TypedArray(dataType);
for (var i:* in args)
{
// push()
[Link](args[i]);
}
return ([Link](this, passArgs));
}

208

splice()

splice() 2 args
for splice()
args Array TypedArray
[Link]() for..in args
2 splice()

AS3 override function splice(...args):*


{
if ([Link] > 2)
{
for (var i:int=2; i< [Link]; i++)
{
if (!(args[i] is dataType))
{
[Link](i,1);
}
}
}
return ([Link](this, args));
}

unshift() unshift()
push()
AS3 override function unshift(...args):uint
{
for (var i:* in args)
{
if (!(args[i] is dataType))
{
[Link](i,1);
}
}
return ([Link](this, args));
}
}

209

PlayList
PlayList

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/PlayList PlayList

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/playlist/
[Link]

PlayList
Song

com/example/programmingas3/playlist/
[Link]

Song
Song

PlayList
PlayList Song addSong()
sortList()
songListPlayList Array

public class PlayList


{
private var _songs:Array;
private var _currentSort:SortProperty = null;
private var _needToSort:Boolean = false;
...
}

PlayList _songs Array


(_needToSort)
(_currentSort)

210

Array Array Array


PlayList
public function PlayList()
{
this._songs = new Array();
//
[Link]([Link]);
}

_songs
sortList()

PlayList addSong()

/**
*
*/
public function addSong(song:Song):void
{
this._songs.push(song);
this._needToSort = true;
}

addSong() _songs push() addSong() Song


push()
push()
_needToSort true sortList()

PlayList Song
PlayList

PlayList

211


Song

SortProperty
public static const TITLE:SortProperty = new SortProperty("title");
public static const ARTIST:SortProperty = new SortProperty("artist");
public static const YEAR:SortProperty = new SortProperty("year");

SortProperty TITLEARTIST YEAR


Song
PlayList sortList()

//
[Link]([Link]);

[Link]

PlayList sortList()
/**
*
*/
public function sortList(sortProperty:SortProperty):void
{
...
var sortOptions:uint;
switch (sortProperty)
{
case [Link]:
sortOptions = [Link];
break;
case [Link]:
sortOptions = [Link];
break;
case [Link]:
sortOptions = [Link];
break;
}
//
this._songs.sortOn([Link], sortOptions);
//
this._currentSort = sortProperty;
//
this._needToSort = false;
}

212


switch sortProperty
sortOptions

sortOn()
_songs

PlayList Song
Song
private var _genres:String;
public function Song(title:String, artist:String, year:uint,
filename:String, genres:Array)
{
...
//
//
this._genres = [Link](";");
}

Song genres
Array Song
_genres String join()
";" Array
genres

Array

public function get genres():Array


{
//
// Array
return this._genres.split(";");
}
public function set genres(value:Array):void
{
//
//
this._genres = [Link](";");
}
genres set Array join()
Stringget _genres split()
";"

PlayList

213

214

ActionScript 3.0

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .222
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .223
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .228
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .232
CustomErrors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .236

215

Adobe Flash Player ActionScript ActionScript


ActionScript

SWF
55
3 ActionScript 115 4 ActionScript

if..then..else

ActionScript

ActionScript

ActionScript

Flash Player

Flash Player Flash


Player Flash
Player
ActionScript 3.0

216

(Asynchronous)

(Catch)
Flash Player ActionScript

(Debugger version) Flash Player


Flash Player
Flash Player ActionScript Adobe Flash CS3
Professional Adobe Flex

(Exception) Flash

(Re-throw)Flash Player

(Synchronous)

(Throw) Flash Player


Player

ActionScript

217

trace()
1.

Flash

2.
3.
4. >

trace

1.

Flash

2.

3.
4.
5.
6.

ActionScript Flash
ErrorTest
[Link] ActionScript
ActionScript
Flash
ActionScript
>
trace()

53

ActionScript

Adobe Flash

Player 9 SWF

Web

218

Flash Player
catch

browse()
var fileRef:FileReference = new FileReference();
try
{
[Link]("[Link]
}
catch (error:IllegalOperationError)
{
trace(error);
// #2037
//
}

browse()

Flash Player

223

browse()
Flash Player open
complete
addEventListener()

var fileRef:FileReference = new FileReference();


[Link]([Link], selectHandler);
[Link]([Link], openHandler);
[Link]([Link], completeHandler);
[Link]();
function selectHandler(event:Event):void
{
trace("...select...");
var request:URLRequest = new URLRequest("[Link]
[Link]");
[Link] = [Link];
[Link]([Link]);

219

}
function openHandler(event:Event):void
{
trace("...open...");
}
function completeHandler(event:Event):void
{
trace("...complete...");
}

229

catch
catch

SWF
Flash Player
Flash Player
trace
Error
getStackTrace() trace
Flash Player 222 Flash Player

ActionScript 3.0

ActionScript 2.0 Error


ActionScript 3.0

220

ActionScript 3.0

ActionScript 3.0
ActionScript 3.0

ECMAScript (ECMA-262) 4 ActionScript 3.0


MemoryError ArgumentError
URIError
232

Flash Player throw


Flash Player 9 ActionScript

Flash Player

222 Flash Player

Flash Player
upload() [Link]() false
ActionScript 3.0 upload()

ActionScript 2.0 FileReference name null


name null
ActionScript 3.0 name Flash Player
IllegalOperationError try..catch..finally
223 try..catch..finally

ActionScript try..catch..finally

ErrorEvent 229

ActionScript 3.0

221

try..catch..finally

223 try..catch..finally

Error

try..catch..finally 228

try..catch..finally
229

Flash Player
Adobe Flash Player Adobe Flash
CS3 Professional Adobe Flex Builder 2 Flash Player
Flash Player
IOError EOFError

try
{
[Link] = [Link]();
}
catch (error:EOFError)
{
[Link] = [Link]();
}

readBoolean() Flash Player EOFError tf


EOFError: #2030:
Flash Player EOFError: #2030
Flash Player
ActionScript 3.0
Flash Player

222

try..catch..finally
(try) (catch) Flash Player
(finally)

try..catch..finally
try..catch..finally
Flash Player Flash Player
Error Error catch
try catch try

try try catch


finally try
finally try
catch finally

try..catch..finally
try
{
//
}
catch (err:Error)
{
//
}
finally
{
//
//
}

catch catch Error


catch catch
Error Error
Error
try
{
throw new ArgumentError("I am an ArgumentError");
}
catch (error:Error)

223

{
trace("<Error> " + [Link]);
}
catch (error:ArgumentError)
{
trace("<ArgumentError> " + [Link]);
}

<Error> I am an ArgumentError

ArgumentError

try
{
throw new ArgumentError("I am an ArgumentError");
}
catch (error:ArgumentError)
{
trace("<ArgumentError> " + [Link]);
}
catch (error:Error)
{
trace("<Error> " + [Link]);
}

Flash Player API


Sound close() IOError

var mySound:Sound = new Sound();


try
{
[Link]();
}
catch (error:IOError)
{
// #2029 URLStream
}

ActionScript 3.0

224

throw

Flash Player
Error
throw Error MyErr
throw Adobe
myFunction()
var MyError:Error = new Error("Encountered an error with the numUsers value",
99);
var numUsers:uint = 0;
try
{
if (numUsers == 0)
{
trace("numUsers equals 0");
}
}
catch (error:uint)
{
throw MyError; //
}
catch (error:int)
{
throw MyError; //
}
catch (error:Number)
{
throw MyError; //
}
catch (error:*)
{
throw MyError; //
}
finally
{
myFunction(); //
}

catch
Number catch uint
catch int catch

Java
throw ActionScript

225

try..catch
package
{
import [Link];
import [Link];
public class SimpleError extends Sprite
{
public var employee:XML =
<EmpCode>
<costCenter>1234</costCenter>
<costCenter>1-234</costCenter>
</EmpCode>;
public function SimpleError()
{
try
{
if ([Link]() != 1)
{
throw new Error("Error, employee must have exactly one cost
center assigned.");
}
}
catch (error:Error)
{
var errorMessage:TextField = new TextField();
[Link] = [Link];
[Link] = 0xFF0000;
[Link] = [Link];
addChild(errorMessage);
}
}
}
}

ActionScript ActionScript 3.0

226

try..catch catch
ApplicationError
try
{
try
{
trace("<< try >>");
throw new ArgumentError("some error which will be rethrown");
}
catch (error:ApplicationError)
{
trace("<< catch >> " + error);
trace("<< throw >>");
throw error;
}
catch (error:Error)
{
trace("<< Error >> " + error);
}
}
catch (error:ApplicationError)
{
trace("<< catch >> " + error);
}

<<
<<
<<
<<

try >>
catch >> ApplicationError: some error which will be rethrown
throw >>
catch >> ApplicationError: some error which will be rethrown

try ApplicationError catch


catch ApplicationError
catch try..catch

227

ActionScript

Flash Player
Error try..catch

toString()
lookupErrorString()

AppError

ActionScript Error

public class AppError extends Error


{
public function AppError(message:String, errorID:int)
{
super(message, errorID);
}
}

AppError
try
{
throw new AppError("Encountered Custom AppError", 29);
}
catch (error:AppError)
{
trace([Link] + ": " + [Link])
}

228

[Link]() ...
ECMAScript (ECMA-262) 3 [Link]()
ActionScript 3.0
[Link]() toString()


ActionScript 3.0
218

XMLSocket
[Link] [Link]
[Link] SecurityErrorEvent.SECURITY_ERROR
267 10

ErrorEvent

[Link] Flash Player


AsyncErrorEventIOErrorEvent SecurityErrorEvent
ErrorEvent Flash Player

netStatus status Flash


Player [Link] [Link]
"error"
level "error"

ErrorEvent Flash Player


try..catch

package
{
import
import
import
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

public class LinkEventExample extends Sprite


{

229

private var myMP3:Sound;


public function LinkEventExample()
{
myMP3 = new Sound();
var list:TextField = new TextField();
[Link] = [Link];
[Link] = true;
[Link] = "<a href=\"event:track1.mp3\">Track 1</a><br>";
[Link] += "<a href=\"event:track2.mp3\">Track 2</a><br>";
addEventListener([Link], linkHandler);
addChild(list);
}
private function playMP3(mp3:String):void
{
try
{
[Link](new URLRequest(mp3));
[Link]();
}
catch (err:Error)
{
trace([Link]);
//
}
[Link](IOErrorEvent.IO_ERROR, errorHandler);
}
private function linkHandler(linkEvent:TextEvent):void
{
playMP3([Link]);
//
}
private function errorHandler(errorEvent:IOErrorEvent):void
{
trace([Link]);
//
}
}
}

230


level Flash Player [Link]
[Link] [Link] NetConnection
NetStream SharedObject [Link] HTTPStatusEvent
Camera Microphone LocalConnection level

netStatusHandler() level level


Video stream failed
package
{
import
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

public class VideoExample extends Sprite


{
private var videoUrl:String = "[Link]";
private var connection:NetConnection;
private var stream:NetStream;
public function VideoExample()
{
connection = new NetConnection();
[Link](NetStatusEvent.NET_STATUS,
netStatusHandler);
[Link](SecurityErrorEvent.SECURITY_ERROR,
securityErrorHandler);
[Link](null);
}
private function netStatusHandler(event:NetStatusEvent):void
{
if ([Link] = "error")
{
trace(" ")
}
else
{
connectStream();
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void

231

{
trace("securityErrorHandler: " + event);
}
private function connectStream():void
{
var stream:NetStream = new NetStream(connection);
var video:Video = new Video();
[Link](stream);
[Link](videoUrl);
addChild(video);
}
}
}

ActionScript Flash Player


ActionScript 3.0
ActionScript [Link] ECMAScript (ECMA-262)
4 [Link] ActionScript 3.0

ECMAScript
ECMAScript Error EvalError RangeError ReferenceError
SyntaxError TypeError URIError

Error

Error
ECMAScript
EvalError RangeError
ReferenceError SyntaxError
TypeError URIError

Error Flash Player

EvalError

Function

eval() EvalError

ActionScript 3.0 eval()

Flash Player eval()

RangeError

Timer
RangeError
RangeError
RangeError

232

ReferenceError

ReferenceError
ActionScript 3.0
ActionScript

ECMAScript
ActionScript
3.0 ReferenceError

ActionScript

SyntaxError

ActionScript SyntaxError
SyntaxError RegExp
ActionScript SyntaxError
ECMAScript (ECMA-262) 3 XMLDocument XML
ActionScript SyntaxError
4

[Link] [Link]/publications/
standards/[Link]
ECMAScript for
XML (E4X) ECMA-357
2 10.3.1 [Link]/publications/
standards/[Link]

TypeError

TypeError

ECMAScript [Link]
[Link]/
publications/standards/[Link]
E4X 10.3 [Link]/publications/
standards/[Link]

URIError

TypeError


is instanceof

super


RegExp

TypeError

URI URIError
URI Flash Player API
URIError
[Link]() URI

ECMAScript [Link]
[Link]/
publications/standards/[Link]

233

ActionScript
ECMAScript ActionScript ActionScript

ECMAScript 4 ActionScript
[Link]

ArgumentError

ArgumentError

SecurityError


SecurityError

URL

1024

VerifyError

SWF SWF SWF


VerifyError SWF
SWF VerifyError

234

[Link]
[Link] Flash Player API
[Link] Flash Player

EOFError

IDataInput
EOFError
EOFError

IllegalOperationError

DisplayObjectContainer

IllegalOperationError

[Link]
Flash Player
IllegalOperationError
Stage


Flash Player

Flash Player


IOError

I/O
IOError
/

MemoryError

MemoryError

ActionScript Virtual
Machine 2 ActionScript

PC

PC
3 GB
32 Microsoft
Windows 2 GB

235

ScriptTimeoutError

15
ScriptTimeoutError
ScriptTimeoutError

ScriptTimeoutError
ScriptTimeoutError

StackOverflowError

StackOverflowError
StackOverflowError

CustomErrors
CustomErrors

XML

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/CustomError CustomErrors

[Link]

Flash (FLA) Flex (MXML)

[Link]
com/example/programmingas3/errors/
[Link]

FatalError WarningError

com/example/programmingas3/errors/
[Link]

FatalError
ApplicationError

com/example/programmingas3/errors/
[Link]

XML

com/example/programmingas3/errors/
[Link]

WarningError
ApplicationError

236

CustomErrors
[Link]
creationComplete initApp() Validator
XML initApp()
private function initApp():void
{
employeeXML =
<employee id="12345">
<firstName>John</firstName>
<lastName>Doe</lastName>
<costCenter>12345</costCenter>
<costCenter>67890</costCenter>
</employee>;
}

TextArea
XML

XML

Validate validateData() Validator


XML validateData()

validateEmployeeXML()

public function validateData():void


{
try
{
var tempXML:XML = XML([Link]);
[Link](tempXML);
[Link] = "The XML was successfully validated.";
}
catch (error:FatalError)
{
showFatalError(error);
}
catch (error:WarningError)
{
showWarningError(error);
}
catch (error:Error)
{
showGenericError(error);
}
}

CustomErrors

237

TextArea xmlText XML


Validator ([Link].programmingas3/errors/[Link])
validateEmployeeXML() XML
XML Label status
validateEmployeeXML() FatalError
WarningError Error catch
showFatalError() showWarningError() showGenericError()
Alert
Label status
XML Alert
TextArea xmlText Button validateBtn
public function showFatalError(error:FatalError):void
{
var message:String = [Link] + "\n\n" + "Click OK to end.";
var title:String = [Link]();
[Link](message, title);
[Link] = "This application has ended.";
[Link] = false;
[Link] = false;
}

Alert
TextField Button showWarningError() Alert
XML
showWarningError()
public function showWarningError(error:WarningError):void
{
var message:String = [Link] + "\n\n" + "Do you want to exit this
application?";
var title:String = [Link]();
[Link](message, title, [Link] | [Link], null, closeHandler);
[Link] = message;
}

Yes No Alert closeHandler()


closeHandler()
private function closeHandler(event:CloseEvent):void
{
switch ([Link])
{
case [Link]:
showFatalError(new FatalError(9999));
break;
case [Link]:
break;
}
}

238

Alert

Yes FatalError

Validator validateEmployeeXML() validateEmployeeXML()


employee XML validateEmployeeXML()

public static function validateEmployeeXML(employee:XML):void


{
// checks for the integrity of items in the XML
if ([Link]() < 1)
{
throw new FatalError(9000);
}
if ([Link]() > 1)
{
throw new WarningError(9001);
}
if ([Link]() != 1)
{
throw new FatalError(9002);
}
}


FatalError validateData()
WarningError XML
XML ssn ssn
FatalError
validateEmployeeXML() ssn

XML ID ID

CustomErrors

239

ApplicationError
ApplicationError FatalError WarningError ApplicationError
Error ID
XML

ApplicationError
public function ApplicationError()
{
messages =
<errors>
<error code="9000">
<![CDATA[Employee must be assigned to a cost center.]]>
</error>
<error code="9001">
<![CDATA[Employee must be assigned to only one cost center.]]>
</error>
<error code="9002">
<![CDATA[Employee must have one and only one SSN.]]>
</error>
<error code="9999">
<![CDATA[The application has been stopped.]]>
</error>
</errors>;
}

XML E4X
getMessageText()
public function getMessageText(id:int):String
{
var message:XMLList = [Link].(@code == id);
return message[0].text();
}
getMessageText() id id
9001 id Employee must be
assigned to only one cost center
ActionScript XMLList
message[0]

getTitle()
ID Alert XML
getTitle()
public function getTitle():String
{
return "Error #" + id;
}

240

ApplicationError toString() Error

public override function toString():String


{
return "[APPLICATION ERROR #" + id + "] " + message;
}

FatalError
FatalError ApplicationError FatalError
getTitle() toString() FatalError
errorID ApplicationError
ApplicationError getMessageText() FatalError

public function FatalError(errorID:int)


{
id = errorID;
severity = [Link];
message = getMessageText(errorID);
}

FatalError getTitle() ApplicationError


getTitle() -- FATAL
getTitle()
public override function getTitle():String
{
return "Error #" + id + " -- FATAL";
}

toString()
toString()

ApplicationError toString()

public override function toString():String


{
return "[FATAL ERROR #" + id + "] " + message;
}

CustomErrors

241

WarningError
WarningError ApplicationError

[Link]
public function WarningError(errorID:int)
{
id = errorID;
severity = [Link];
message = [Link](errorID);
}

242

FatalError
[Link]

/A\d+/

ActionScript 3.0 ECMAScript 3


(ECMA-262)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .244
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .246
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Wiki . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .262

243

ABC
ABC
A B C
/ABC/

(/)

/([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}/

String String
match() replace() search() split()
179

RegExp test() exec() 260

7 10
a m

244

(Escape character)
(\)

(Flag)

(Metacharacter)

(Quantifier)
5 9

(Regular expression)

1.

Flash

2.
3.

RegExp

var pattern:RegExp = /ABC/;

RegExp
(/ABC/)

4.

5.

String

String
var goodEmail:String = "bob@[Link]";
var badEmail:String = "5@$2.99";

6.

String
trace()
trace(goodEmail, " is valid:", [Link](goodEmail));
trace(badEmail, " is valid:", [Link](badEmail));

245

pattern

bob@[Link] is valid: true
5@$2.99 is valid: false

trace()
53

ActionScript

ActionScript 3.0 ECMAScript 3


(ECMA-262)

A B C
/ABC\d/
\d (\)

ABC
/ABC\d*/

(*)

252

i
/ABC\d*/i

257
String match() replace() search()
179

246


(/)
new
var pattern1:RegExp = /bob/i;
var pattern2:RegExp = new RegExp("bob", "i");

new

var pattern2:RegExp = new RegExp("bob", "i");

(\) 1/2
var pattern:RegExp = /1\/2/;

new (\)
String eat at "joe's"

var pattern1:RegExp = new RegExp("eat at \"joe's\"", "");


var pattern2:RegExp = new RegExp('eat at "joe\'s"', "");

new
1/2 "joe's"
var pattern1:RegExp = /1\/2 "joe's"/;
var pattern2:RegExp = new RegExp("1/2 \"joe's\"", "");
var pattern3:RegExp = new RegExp('1/2 "joe\'s"', '');

new (\)
\d
var pattern:RegExp = new RegExp("\\d+", ""); //

RegExp()

257

247

var pattern:RegExp = /hello/;


^ $ \ . * + ? ( ) [ ] { } |

A B

/AB*C/

(\)
A B C
var pattern:RegExp = /AB\*C/;

m (multiline)
258 m (multiline)
250

m (multiline) $ (\n)
258 m (multiline)

/1\/2/ 1 2

s (dotall) (\n)
258 s (dotall)

252

252

252

248

()

| /(a|b|c)d/
/(walla.){1,2}/
\1

/(\w*) is repeated: \1/

254
[]

/[aeiou]/
(-)
/[A-Z0-9]/ A Z 0 9
]
-
/[+\-]\d+/ + -

/[$]/ $
250


/abc|xyz/ abc xyz

{n}
{n,}

/A{27}/ 27 A
/A{3,}/ 3 A
/A{3,5}/ 3 5 A
252

{n,n}

\b

\B

\d

\D

\f

\n

\r

249

\s

\S

\t

\unnnn

nnnn Unicode \u263a

\v

\w

A-Z a-z 0-9 _ \w


\W

\xnn

ASCII nn

[ ]
bag beg big bog bug
/b[aeiou]g/

/[abc*123]/

251


$\] -
/[$\\\]\-]/

250

\n

\r

\t

\unnnn

Unicode nnnn

\xnn

ASCII nn

A-Z a-z 0-9


a-z
/[a-z0-9]/

\xnn ASCII ASCII


ASCII
/[\x80-\x9A]/

(^)
(a-z)
/[^a-z0-9]/

(^)

/[!.,#+*%$&^]/

251

{n}
{n,}

/A{27}/ 27 A
/A{3,}/ 3 A
/A{3,5}/ 3 5 A

{n,n}

/a+/ a

/\d+/

/[abc]+/ a b c

/(very, )*/ very

word word-word-word
/\w+(-\w+)*/

.*

var pattern:RegExp = /<p>.*<\/p>/;


str:String = "<p>Paragraph 1</p> <p>Paragraph 2</p>";

<p>Paragraph 1</p> <p>Paragraph 2</p>

<p>...</p>
<p>Paragraph 1</p>

(?)
*? <p> </p>
/<p>.*?<\/p>/

252

{0} {0,0}

/abc+*/

s (dotall)

(.)

var str:String = "<p>Test\n";


str += "Multiline</p>";
var re:RegExp = /<p>.*<\/p>/;
trace([Link](re)); // null
re = /<p>.*<\/p>/s;
trace([Link](re));
// <p>Test
//
Multiline</p>

258 s (dotall)


|
cat dog pig rat
var pattern:RegExp = /cat|dog|pig|rat/;

| cat
nap nip
var pattern:RegExp = /cat(nap|nip)/;

254
| [ ]

/1|3|5|7|9/
/[13579]/

250

253

/class-(\d*)/

\1
String replace() $1

var pattern:RegExp = /ab*/ ;


// a
// b
pattern = /a\d+/;
// a
//
pattern = /a[123]{1,3}/;
// a
// 1 2 3

var pattern:RegExp = /(ab)*/;


// a
// b ababab
pattern = /(a\d)+/;
// a
// a1a5a8a3
pattern = /(spam ){1,3}/;
// 1 3 spam

252

254

(|)
(|)
var pattern:RegExp = /cat|dog/;
// cat dog
pattern = /ca(t|d)og/;
// catog cadog

\1

var pattern:RegExp = /(\d+)-by-\1/;


// 48-by-48

\1, \2,

... , \99 99

String replace() $1-$99

var pattern:RegExp = /Hi, (\w+)\./;


var str:String = "Hi, Bob.";
trace([Link](pattern, "$1, hello."));
// Bob, hello.

RegExp exec() String match()

var pattern:RegExp = /(\w+)@(\w+).(\w+)/;


var str:String = "bob@[Link]";
trace([Link](str));
// bob@[Link],bob,example,com

(?:
)
var pattern = /(?:com|org|net);

(com|org) exec()

var pattern:RegExp = /(\w+)@(\w+).(com|org)/;


var str:String = "bob@[Link]";
trace([Link](str));
// bob@[Link],bob,example,com

255

//
var pattern:RegExp = /(\w+)@(\w+).(?:com|org)/;
var str:String = "bob@[Link]";
trace([Link](str));
// bob@[Link],bob,example

(?= )
(?=e)
e \w*)
var pattern:RegExp = /sh(?=e)(\w*)/i;
var str:String = "Shelly sells seashells by the seashore";
trace([Link](str));
// Shelly,elly

(?! )
var pattern:RegExp = /sh(?!e)(\w*)/i;
var str:String = "She sells seashells by the seashore";
trace([Link](str));
// shore,ore

(?P<name> )
digits
var pattern = /[a-z]+(?P<digits>\d+)[a-z]+/;

exec() result
var myPattern:RegExp = /([a-z]+)(?P<digits>\d+)[a-z]+/;
var str:String = "a123bcd";
var result:Array = [Link](str);
trace([Link]); // 123

name dom
var emailPattern:RegExp =
/(?P<name>(\w|[_.\-])+)@(?P<dom>((\w|-)+))+\.\w{2,4}+/;
var address:String = "bob@[Link]";
var result:Array = [Link](address);
trace([Link]); // bob
trace([Link]); //

256

ECMAScript ActionScript 3.0

global

ignoreCase

A-Z a-z

multiline

$ ^

dotall

. (\n)

extended

gims
x
var re:RegExp = /abc/gimsx;

var re:RegExp = /abc/;


[Link] = true; //

false

lastIndex exec() test()

source

g (global)
g (global)
g [Link]()
var str:String = "she sells seashells by the seashore.";
var pattern:RegExp = /sh\w*/;
trace([Link](pattern)) // she

g [Link]()
var str:String = "she sells seashells by the seashore.";
var pattern:RegExp = /sh\w*/g;
// g
trace([Link](pattern)); // she,shells,shore

257

i (ignoreCase)
i (ignoreCase)
s S
var str:String = "She sells seashells by the seashore.";
trace([Link](/sh/)); // 13 --

i S
var str:String = "She sells seashells by the seashore.";
trace([Link](/sh/i)); // 0
i A-Z a-z

m (multiline)
m (multiline) ^ $
m
var str:String = "Test\n";
str += "Multiline";
trace([Link](/^\w*/g)); //

g (global) match()
^
Test

m
var str:String = "Test\n";
str += "Multiline";
trace([Link](/^\w*/gm)); //

Test,Multiline

\n

(\r)

Unicode (\u2028)
Unicode (\u2029)

s (dotall)
sdotall dot all (.) (\n)

var str:String = "<p>Test\n";


str += "Multiline</p>";
var re:RegExp = /<p>.*?<\/p>/;
trace([Link](re));

258

s
var str:String = "<p>Test\n";
str += "Multiline</p>";
var re:RegExp = /<p>.*?<\/p>/s;
trace([Link](re));

<p>
<p>Test
Multiline</p>

x (extended)

/<p(>|(\s*[^>]*>)).*?<\/p>/gi

x (extended)

<p

(>

(\s*

[^>]*

>))

.*?

<\/p>

/gix

/foo bar/
/foo \ bar/x

lastIndex
lastIndex g true

exec() test()

var pattern:RegExp = /p\w*/gi;


var str:String = "Pedro Piper picked a peck of pickled peppers.";
trace([Link]);
var result:Object = [Link](str);
while (result != null)
{
trace([Link]);
result = [Link](str);
}

259

lastIndex 0

0
5
11
18
25
36
44

global false exec() test() lastIndex

String match() replace() search()


lastIndex match()
lastIndex 0
lastIndex

source
source
var pattern:RegExp = /foo/gi;
trace([Link]); // foo

RegExp exec() test()


RegExp exec() test() String
match() replace() search() splice()

test()
RegExp

test()

var pattern:RegExp = /Class-\w/;


var str = "Class-A";
trace([Link](str)); // true

260

exec()
RegExp exec()

index

var pattern:RegExp = /\d{3}\-\d{3}-\d{4}/; //


var str:String = "phone: 415-555-1212";
var result:Array = [Link](str);
trace([Link], " - ", result);
// 7 - 415-555-1212

g (global) exec()
var pattern:RegExp = /\w*sh\w*/gi;
var str:String = "She sells seashells by the seashore";
var result:Array = [Link](str);
while (result != null)
{
trace([Link], "\t", [Link], "\t", result);
result = [Link](str);
}
//
// 0 3 She
// 10 19 seashells
// 27 35 seashore

RegExp String
String match() replace() search() split()
179

261

Wiki
Wiki

Wiki HTML

URL HTML <a>

"$9.95" "8.24 "

[Link]/go/learn_programmingAS3samples_flash_cn WikiEditor
Samples/WikiEditor

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/
regExpExamples/[Link]

Wiki
HTML

com/example/programmingas3/
regExpExamples/[Link]

URL
HTML <a>

com/example/programmingas3/
regExpExamples/[Link]

WikiParser
WikiParser Wiki HTML
Wiki

setWikiData()

public function WikiParser()


{
wikiData = setWikiData();
}

262

Wiki

Test WikiParser
parseWikiString() HTML

public function parseWikiString(wikiString:String):String


{
var result:String = parseBold(wikiString);
result = parseItalic(result);
result = linesToParagraphs(result);
result = parseBullets(result);
return result;
}

parseBold() parseItalic() linesToParagraphs()


parseBullets() replace()
Wiki HTML

parseBold() Wiki '''foo'''

HTML

<b>foo</b>
private function parseBold(input:String):String
{
var pattern:RegExp = /'''(.*?)'''/g;
return [Link](pattern, "<b>$1</b>");
}

(.?*) ''' (*) ?


'''aaa''' bbb '''ccc'''
'''aaa''' '''
replace() $1
g (global) replace()

parseItalic() parseBold()
('')
private function parseItalic(input:String):String
{
var pattern:RegExp = /''(.*?)''/g;
return [Link](pattern, "<i>$1</i>");
}

Wiki

263


parseBullet() Wiki * foo
HTML <li>foo</li>
private function parseBullets(input:String):String
{
var pattern:RegExp = /^\*(.*)/gm;
return [Link](pattern, "<li>$1</li>");
}

^ m (multiline)
^
\* *

replace() $1
g (global) replace()

Wiki
linesToParagraphs() Wiki
Wiki

HTML <p>

var pattern:RegExp = /^$/gm;


var result:String = [Link](pattern, "");

^ $ m (multiline)
^
replace() ("") g

(global) replace()

URL HTML <a>


Test urlToATag
[Link]() URL Wiki
HTML <a>
var
var
var
var

protocol:String = "((?:http|ftp)://)";
urlPart:String = "([a-z0-9_-]+\.[a-z0-9_-]+)";
optionalUrlPart:String = "(\.[a-z0-9_-]*)";
urlPattern:RegExp = new RegExp(protocol + urlPart + optionalUrlPart,
"ig");
var result:String = [Link](urlPattern,
"<a href='$1$2$3'><u>$1$2$3</u></a>");
RegExp() (urlPattern)

264

protocol URL http:// ftp://


? |
replace() $1 $2 $3
replace()
$1 $2 $3
urlPart a-z0-9_ -+
\. (.)
a-z 0-9 _ -
optionalUrlPart (.)
_ - *
replace()

HTML
urlToATag() emailToATag() HTML <a>
HTTPFTP URL
URL

Test dollarToEuro
[Link]() "$9.95"
"8.24 "
var usdPrice:RegExp = /\$([\d,]+.\d+)+/g;
return [Link](usdPrice, usdStrToEuroStr);

$ (\)
replace() usdStrToEuroStr()


replace()

[Link] - 3

Wiki

265

usdStrToEuroStr()
private function usdToEuro(...args):String
{
var usd:String = args[1];
usd = [Link](",", "");
var exchangeRate:Number = 0.828017;
var euro:Number = Number(usd) * exchangeRate;
trace(usd, Number(usd), euro);
const euroSymbol:String = [Link](8364); //
return [Link](2) + " " + euroSymbol;
}

args[1] usdPrice
$
$

266

10

10

ActionScript 3.0
Adobe Flash Player 9
(DOM) 3
ActionScript
ActionScript
ActionScript 3.0

319

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .268
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . 271
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .279
Alarm Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .286

267

SWF
SWF
SWF

ActionScript 3.0 Event

Flash Player MouseEvent

Flash Player

Flash Player

function eventResponse(eventObject:EventType):void
{
//
}
[Link](EventType.EVENT_NAME, eventResponse);

addEventListener()

268


eventResponse
EventType
EVENT_NAME
eventTarget addEventListener()
eventObject

(Default behavior)

(Dispatch)

(Event)

(Event flow)

(Event object)

269

(Event target) Sprite

(Listener)

trace()

1.

Flash

2.
3.
4. >

trace

1.

Flash

2.

3.
4.
5.
6.

ActionScript Flash
EventTest
[Link] ActionScript
ActionScript
Flash
ActionScript
>

270

53

ActionScript 3.0

ActionScript 3.0 ActionScript


ActionScript 3.0 ActionScript
ActionScript
ActionScript 3.0

ActionScript
ActionScript 3.0 ActionScript

on() Button MovieClip

onClipEvent() MovieClip

[Link] [Link]

addListener()

DOM

UIEventDispatcher

on() onClipEvent()

ActionScript 2.0 UIEventDispatcher


DOM
ActionScript 3.0

ActionScript 2.0 [Link]


UIEventDispatcher
KeyMouseMovieClipLoaderSelection
Stage TextField addListener()
addEventListener()

this

ActionScript 3.0

271

ActionScript 3.0
ActionScript 3.0
(DOM) 3 SWF
DOM
DOM DOM

Flash Player DOM


Flash Player

Flash Player Flash


Player
TextField TextField
Flash Player
TextField Flash Player TextEvent
Flash Player TextField
TextEvent preventDefault()
TextField Flash Player
MouseEvent
Flash Player
Event API

Flash Player ActionScript


EventDispatcher
textInput Flash
Player textInput TextField

272

ActionScript 3.0
ActionScript 2.0 addListener() ActionScript 2.0
ActionScript 3.0

ActionScript 2.0 addListener()


addEventListener() ActionScript 3.0
addEventListener()

ActionScript 2.0 addListener()


ActionScript 3.0
addEventListener()

ActionScript 2.0

ActionScript 3.0

Flash Player Flash


Player Flash Player progress
URLStream Flash Player

[Link]
stage
Flash Player
DOM
child1 Flash Player
child1

273

Stage

Parent Node

Child2 Node

Child1 Node

Child1Flash Player
Stage Parent Child1
Stage Parent Stage

Stage Parent Child1


Parent Stage
ActionScript
ActionScript
ActionScript 3.0

274

enterFrame
init
Socket

API

Flash Player API Event


Event

Event Event Event

Event
Event

[Link]

[Link]

[Link]

clickHandler() myDisplayObject

[Link]([Link], clickHandler);

275

20 Event Event
Event
package [Link]
{
public class Event
{
//
public static const ACTIVATE:String = "activate";
public static const ADDED:String
= "added";
//
}
}

[Link]([Link], clickHandler);

[Link]("click", clickHandler);

cancelable
cancelable
preventDefault()
279

Event

bubbles

eventPhase

target

currentTarget

276

bubbles

[Link]

true
false

eventPhase
eventPhase eventPhase
Flash Player API
EventPhase
package [Link]
{
public final class EventPhase
{
public static const CAPTURING_PHASE:uint = 1;
public static const AT_TARGET:uint
= 2;
public static const BUBBLING_PHASE:uint = 3;
}
}

eventPhase
myFunc()

if ([Link] == EventPhase.AT_TARGET)
{
myFunc();
}

target
target

Microphone

Flash Player
SWF SWF
target
currentTarget
target

277

currentTarget
currentTarget

currentTarget

Event
Event

Event
Event clone() toString()

Event

[Link]() [Link]()

[Link]()

[Link]()

278

Event


preventDefault() isDefaultPrevented()
preventDefault()
preventDefault() isDefaultPrevented()
true false
preventDefault()

API ActionScript cancelable


Event

Event
Event Event
Flash Player API Event

Event MouseEvent 10
Event 10

Event MouseEvent
click doubleClick mouseDown mouseUp

278 Event Event

clone() toString()

Flash Player
Flash Player
addEventListener()

ActionScript 3.0 DOM


DOM
EventListener handleEvent() DOM

279

ActionScript 3.0 ActionScript 3.0


EventListener
handleEvent()
ActionScript 3.0

SWF clickHandler()

package
{
import [Link];
public class ClickExample extends Sprite
{
public function ClickExample()
{
var child:ChildSprite = new ChildSprite();
addChild(child);
}
}
}
import [Link];
import [Link];
class ChildSprite extends Sprite
{
public function ChildSprite()
{
[Link](0xFF0000);
[Link](0,0,100,100);
[Link]();
addEventListener([Link], clickHandler);
}
}
function clickHandler(event:MouseEvent):void
{
trace("clickHandler detected an event of type: " + [Link]);
trace("the this keyword refers to: " + this);
}

SWF Flash
clickHandler detected an event of type: click
the this keyword refers to: [object global]

280

Player

clickHandler()
type
this this

ClickExample clickHandler()
ChildSprite
package
{
import [Link];
public class ClickExample extends Sprite
{
public function ClickExample()
{
var child:ChildSprite = new ChildSprite();
addChild(child);
}
}
}
import [Link];
import [Link];
class ChildSprite extends Sprite
{
public function ChildSprite()
{
[Link](0xFF0000);
[Link](0,0,100,100);
[Link]();
addEventListener([Link], clickHandler);
}
private function clickHandler(event:MouseEvent):void
{
trace("clickHandler detected an event of type: " + [Link]);
trace("the this keyword refers to: " + this);
}
}

SWF Flash

Player

clickHandler detected an event of type: click


the this keyword refers to: [object ChildSprite]

281

this child ChildSprite ActionScript 2.0


ActionScript 2.0
[Link]()
ActionScript 2.0
this ChildSprite

ActionScript 2.0 [Link]


ActionScript 3.0
addEventListener() this child
ChildSprite ChildSprite

ActionScript 2.0
ActionScript 3.0 this

ClickExample
myListenerObj
package
{
import [Link];
public class ClickExample extends Sprite
{
public function ClickExample()
{
var child:ChildSprite = new ChildSprite();
addChild(child);
}
}
}
import [Link];
import [Link];
class ChildSprite extends Sprite
{
public function ChildSprite()
{
[Link](0xFF0000);
[Link](0,0,100,100);
[Link]();
addEventListener([Link], [Link]);

282

}
}
var myListenerObj:Object = new Object();
[Link] = function (event:MouseEvent):void
{
trace("clickHandler detected an event of type: " + [Link]);
trace("the this keyword refers to: " + this);
}

clickHandler detected an event of type: click


the this keyword refers to: [object global]

this myListenerObj [object Object]


addEventListener() Flash Player
listener
Flash Player myListenerObj

IEventDispatcher IEventDispatcher
ActionScript 3.0 DOM EventTarget
IEventDispatcher
IEventDispatcher

package [Link]
{
public interface IEventDispatcher
{
function addEventListener(eventName:String,
listener:Object,
useCapture:Boolean=false,
priority:Integer=0,
useWeakReference:Boolean=false):Boolean;
function removeEventListener(eventName:String,
listener:Object,
useCapture:Boolean=false):Boolean;
function dispatchEvent(eventObject:Event):Boolean;
function hasEventListener(eventName:String):Boolean;
function willTrigger(eventName:String):Boolean;
}
}

283

Flash Player API EventDispatcher IEventDispatcher


DisplayObject EventDispatcher
IEventDispatcher

addEventListener()

IEventDispatcher

type listenertype listener


listener

listener addEventListener()
clickHandler()
addEventListener([Link], clickHandler)

addEventListener() useCapture
useCapture true
useCapture false
addEventListener()
useCapture true useCapture false
addEventListener() priority

DOM Level 3
ActionScript 3.0
addEventListener() priority
0

useWeakReference
true Flash
Player

useWeakReference
false Flash Player
useWeakReference
true removeEventListener()

284


removeEventListener()
eventName listener addEventListener()
addEventListener()
useCapture true false
removeEventListener() useCapture
true false

dispatchEvent()
Event
target dispatchEvent()

IEventDispatcher
hasEventListener() true
willTrigger() true willTrigger()

285


ActionScript 3.0
Flash Player
Flash Player
URL Flash Player

ErrorEvent text
Flash Player StatusEvent NetStatusEvent
level [Link] [Link] level
error
SWF
Adobe Flex Builder 2
Flash Player

Alarm Clock
Alarm Clock
Alarm Clock SimpleClock 5
Alarm Clock ActionScript 3.0

286

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/AlarmClock Alarm Clock

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/clock/
[Link]

SimpleClock

com/example/programmingas3/clock/
[Link]

[Link]
AlarmClock alarm

com/example/programmingas3/clock/
[Link]

SimpleClock

com/example/programmingas3/clock/
[Link]

SimpleClock

Alarm Clock
SimpleClock
166 AlarmClock

SimpleClock
AlarmClock Alarm
AlarmClock Timer
AlarmClock Timer
AlarmClock ActionScript
Alarm Clock

AlarmClock Timer
([Link]) AlarmClock
Timer
import [Link];
import [Link];
/**
* Timer
*/

Alarm Clock

287

public var alarmTimer:Timer;


...
/**
* AlarmClock
*/
public override function initClock(faceSize:Number = 200):void
{
[Link](faceSize);
alarmTimer = new Timer(0, 1);
[Link]([Link], onAlarm);
}

AlarmClock Timer alarmTimer initClock()


AlarmClock alarmTimer
Timer 0 timer alarmTimer
addEventListener() timer Timer
timer AlarmClock
timer addEventListener() AlarmClock
alarmTimer AlarmClock
timer [Link] AlarmClock
onAlarm()
AlarmClock setAlarm()
/**
*
* @param hour
* @param minutes
* @param message
* @return
*/
public function setAlarm(hour:Number = 0, minutes:Number = 0,
message:String = "Alarm!"):Date
{
[Link] = message;
var now:Date = new Date();
//
alarmTime = new Date([Link], [Link], [Link], hour, minutes);
//
if (alarmTime <= now)
{
[Link]([Link] + MILLISECONDS_PER_DAY);
}
//
[Link]();
//
//

288

//
[Link] = [Link](1000, [Link] - [Link]);
[Link]();
return alarmTime;
}

Date (alarmTime)

alarmTimer reset()
alarmTime now
Timer timer
alarmTimer delay start()

alarmTimer timer AlarmClock onAlarm()


timer onAlarm()
/**
* timer
*/
public function onAlarm(event:TimerEvent):void
{
trace("Alarm!");
var alarm:AlarmEvent = new AlarmEvent([Link]);
[Link](alarm);
}


Timer timer TimerEvent
([Link]) Event Timer
TimerEvent

Timer AlarmClock
ActionScript
[Link] [Link]
IEventDispatcher EventDispatcher
AlarmClock SimpleClock SimpleClock Sprite Sprite
EventDispatcher AlarmClock

Alarm Clock

289

AlarmClock EventDispatcher addEventListener()


AlarmClock alarm AlarmClock
alarm dispatchEvent()
EventDispatcher
var alarm:AlarmEvent = new AlarmEvent([Link]);
[Link](alarm);

AlarmClock onAlarm() AlarmClock


dispatchEvent() AlarmClock
alarm dispatchEvent()
AlarmEvent Event

Alarm

Event
Event
AlarmClock alarm
AlarmEvent AlarmEvent alarm

import [Link];
/**
* Event Event message
*/
public class AlarmEvent extends Event
{
/**
* AlarmEvent
*/
public static const ALARM:String = "alarm";
/**
*
*
*/
public var message:String;
/**
*
* @param message
*/
public function AlarmEvent(message:String = "ALARM!")
{
super(ALARM);

290

[Link] = message;
}
...
}

Event
AlarmEvent message
message AlarmEvent AlarmEvent
ALARM AlarmClock addEventListener()
(alarm)
ActionScript Event
clone() Event toString()
toString()
/**
*
* @return
*/
public override function clone():Event
{
return new AlarmEvent(message);
}
/**
*
*
* @return
*/
public override function toString():String
{
return formatToString("AlarmEvent", "type", "bubbles", "cancelable",
"eventPhase", "message");
}

clone() Event
toString() formatToString()
Event

Alarm Clock

291

292

11

11

XML
ActionScript 3.0 ECMAScript for XML (E4X) ECMA-357 2
XML
E4X XML
E4X XML

XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .294
XML E4X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
XMLList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Internet RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314

293

XML
XML
XML
XML eXtensible Markup Language
[Link]/XML/ XML
XML
XML HTML XML
<song>
<title>What you know?</title>
<artist>Steve and the flubberblubs</artist>
<year>1989</year>
<lastplayed>2006-10-17-08:31</lastplayed>
</song>

XML
XML
<album>
<title>Questions, unanswered</title>
<artist>Steve and the flubberblubs</artist>
<year>1989</year>
<tracks>
<song tracknumber="1" length="4:05">
<title>What do you know?</title>
<artist>Steve and the flubberblubs</artist>
<lastplayed>2006-10-17-08:31</lastplayed>
</song>
<song tracknumber="2" length="3:45">
<title>Who do you know?</title>
<artist>Steve and the flubberblubs</artist>
<lastplayed>2006-10-17-08:35</lastplayed>
</song>
<song tracknumber="3" length="5:14">
<title>When do you know?</title>
<artist>Steve and the flubberblubs</artist>
<lastplayed>2006-10-17-08:39</lastplayed>
</song>
<song tracknumber="4" length="4:19">
<title>Do you know?</title>
<artist>Steve and the flubberblubs</artist>
<lastplayed>2006-10-17-08:44</lastplayed>
</song>
</tracks>
</album>

294

XML

XML XML song


XML song tracknumber length
tracks

XML
XML XML
XML
XML XML XML
XML

XML
<song tracknumber="1" length="4:05">
<title>What do you know?</title>
<artist>Steve and the flubberblubs</artist>
<mood>Happy</mood>
<lastplayed>2006-10-17-08:31</lastplayed>
</song>



<title>


</title>

XML

<lastplayed/>

<lastplayed></lastplayed>

XML length 4:19


<song length="4:19"></song>

XML

XML

XML

295

XML
XML
Web

XML

W3Schools XML [Link]


[Link][Link]
XMLpitstop [Link]

XML ActionScript
ActionScript 3.0 XML

XML XML XML

XMLList XML XML


XML XMLList
XMLList XML XML
<artist type="composer">Fred Wilson</artist>
<artist type="conductor">James Schmidt</artist>
<artist type="soloist">Susan Harriet Thurndon</artist>

XML ActionScript Namespace QName


311 XML
XML ActionScript 3.0
XML XML
ECMAScript for XML (E4X) ECMA-357 2

XML
ActionScript

XML

XML

XML

XML

XML

XML

XML

XML

296

XML

String

(Element)XML
XML

(Empty element)
<element/>

(Document) XML XML


XML

(Node)XML

(Attribute) attributename="value"

XML

trace()
1.

Flash

2.
3.
4. >

trace()
53

XML E4X
ECMAScript for XML XML
E4XActionScript 3.0 E4X XMLXMLListQName Namespace
E4X

E4X XML

E4X ActionScript

XML E4X

297

XML (.)

ActionScript 2.0 XML ActionScript 3.0 XMLDocument


E4X ActionScript 3.0 XML ActionScript 3.0
[Link] XMLDocument XMLNode XMLParser XMLTag
E4X
ActionScript 2.0 XML ActionScript 3.0
[Link]

E4X
var myXML:XML =
<order>
<item id='1'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id='2'>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>

Web RSS
XML

XML

E4X (.) (@)


XML (property) (attribute)
trace([Link][0].menuName); // burger
trace([Link].(@id==2).menuName); // fries
trace([Link].(menuName=="burger").price); // 3.95

appendChild() XML
var newItem:XML =
<item id="3">
<menuName>medium cola</menuName>
<price>1.25</price>
</item>
[Link](newItem);

@ .
[Link][0].menuName="regular burger";
[Link][1].menuName="small fries";
[Link][2].menuName="medium cola";
[Link].(menuName=="regular burger").@quantity = "2";
[Link].(menuName=="small fries").@quantity = "2";
[Link].(menuName=="medium cola").@quantity = "2";

298

XML

for XML
var total:Number = 0;
for each (var property:XML in [Link])
{
var q:int = Number(property.@quantity);
var p:Number = Number([Link]);
var itemTotal:Number = q * p;
total += itemTotal;
trace(q + " " + [Link] + " $" + [Link](2))
}
trace("Total: $", [Link](2));

XML
XML XML
XML XML
XML

XML
[Link] = false;
[Link] = false;
var x1:XML =
<order>
<!-- -->
<?PROC_INSTR sample ?>
<item id='1'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id='2'>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>

comments() processingInstructions()
XML
var x2:XML = [Link]()[0];
var x3:XML = [Link]()[0];

XML

299

XML
XML

ignoreComments ignoreProcessingInstructions XML

ignoreWhitespace

prettyIndent prettyPrinting

XML toString()

toXMLString()

ActionScript 3.0

XML
XML

appendChild()

child()

childIndex()

children()

descendants()

elements()

insertChildAfter()

insertChildBefore()

parent()

prependChild()

XML

attribute()

attributes()

XML

hasOwnProperty()

propertyIsEnumerable()

replace()

setChildren()

300

XML

(attribute)

(property)

addNamespace()

inScopeNamespaces()

localName()

name()

namespace()

namespaceDeclarations()

removeNamespace()

setLocalName()

setName()

setNamespace()

XML

comments()

hasComplexContent()

hasSimpleContent()

nodeKind()

processingInstructions()

text()

XML

defaultSettings()

setSettings()

settings()

normalize()

toString()

toXMLString()

contains()

copy()

valueOf()

length()

ActionScript 3.0

XML

301

XMLList
XMLList XML XML XML
XML
XMLList

child()

children()

descendants()

elements()

parent()

XMLList (attribute)

attribute()

attributes()

XMLList (property)

hasOwnProperty()

propertyIsEnumerable()

XML

comments()

hasComplexContent()

hasSimpleContent()

processingInstructions()

text()

XMLList

normalize()

toString()

toXMLString()

contains()

copy()

length()

valueOf()

ActionScript 3.0

302

XML

XML XMLList XML


XML XMLList XML
[Link] XMLList XML appendChild()
var doc:XML =
<body>
<div>
<p>Hello</p>
</div>
</body>;
[Link](<p>World</p>);

XML 299 XML

XML
XML

XML

var myXML:XML =
<order>
<item id='1'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id='2'>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>

new XML XML

var str:String = "<order><item id='1'><menuName>burger</menuName>"


+ "<price>3.95</price></item></order>";
var myXML:XML = new XML(str);

XML
XML
var tagname:String = "item";
var attributename:String = "id";
var attributevalue:String = 5;
var content:String = "Chicken";
var x:XML = <{tagname} {attributename}={attributevalue}>{content}</
{tagname}>;
trace([Link]())
// <item id="5">Chicken</item>

XML

303

URL XML URLLoader


import [Link];
import [Link];
import [Link];
var externalXML:XML;
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("[Link]");
[Link](request);
[Link]([Link], onComplete);
function onComplete(event:Event):void
{
var loader:URLLoader = [Link] as URLLoader;
if (loader != null)
{
externalXML = new XML([Link]);
trace([Link]());
}
else
{
trace("loader is not a URLLoader!");
}
}

XML XMLSocket
ActionScript 3.0 XMLSocket

XML
prependChild() appendChild() XML

var x1:XML = <p>Line 1</p>


var x2:XML = <p>Line 2</p>
var x:XML = <body></body>
x = [Link](x1);
x = [Link](x2);
x = [Link](<p>Line 0</p>);
// x == <body><p>Line 0</p><p>Line 1</p><p>Line 2</p></body>

304

XML

insertChildBefore() insertChildAfter()

var x:XML =
<body>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
</body>
var newNode:XML = <p>Paragraph 1.5</p>
x = [Link](x.p[0], newNode)
x = [Link](x.p[2], <p>Paragraph 1.75</p>)

{ } XML

var ids:Array = [121, 122, 123];


var names:Array = [["Murphy","Pat"], ["Thibaut","Jean"], ["Smith","Vijay"]]
var x:XML = new XML("<employeeList></employeeList>");
for (var i:int = 0; i < 3; i++)
{
var newnode:XML = new XML();
newnode =
<employee id={ids[i]}>
<last>{names[i][0]}</last>
<first>{names[i][1]}</first>
</employee>;
x = [Link](newnode)
}

(property) (attribute) XML

var x:XML =
<employee>
<lastname>Smith</lastname>
</employee>
[Link] = "Jean";
x.@id = "239";

XML x
<employee id="239">
<lastname>Smith</lastname>
<firstname>Jean</firstname>
</employee>

+ += XMLList
var x1:XML = <a>test1</a>
var x2:XML = <b>test2</b>
var xList:XMLList = x1 + x2;
xList += <c>test3</c>

XML

305

XMLList xList
<a>test1</a>
<b>test2</b>
<c>test3</c>

XML
XML
XML ActionScript XML

XML

XMLList XML
(.) (..) XML
XML
var myXML:XML =
<order>
<book ISBN="0942407296">
<title>Baking Extravagant Pastries with Kumquats</title>
<author>
<lastName>Contino</lastName>
<firstName>Chuck</firstName>
</author>
<pageCount>238</pageCount>
</book>
<book ISBN="0865436401">
<title>Emu Care and Breeding</title>
<editor>
<lastName>Case</lastName>
<firstName>Justin</firstName>
</editor>
<pageCount>115</pageCount>
</book>
</order>

[Link] XMLList book myXML


XML myXML book
myXML..lastName XMLList lastName
XML myXML lastName
[Link]

XMLList myXML book


editor lastName XMLList
XML Case lastName

306

XML


parent()

XML

XML myXML
book book
[Link][0]
[Link][1]

[Link][0].title[0]

[Link][0] title
[Link][0].title

x book title

[Link]

child()
var myXML:XML =
<order>
<book>
<title>Dictionary</title>
</book>
</order>;
var childName:String = "book";
trace([Link](childName).title) // Dictionary

XML XMLList

var employee:XML =
<employee id="6401" code="233">
<lastName>Wu</lastName>
<firstName>Erin</firstName>
</employee>;
trace(employee.@id); // 6401

XML

307

* @

XML XMLList

var employee:XML =
<employee id="6401" code="233">
<lastName>Wu</lastName>
<firstName>Erin</firstName>
</employee>;
trace(employee.@*.toXMLString());
// 6401
// 233

attribute() attributes()

XML XMLList

var employee:XML =
<employee id="6401" code="233">
<lastName>Wu</lastName>
<firstName>Erin</firstName>
</employee>;
trace([Link]("id")); // 6401
trace([Link]("*").toXMLString());
// 6401
// 233
trace([Link]().toXMLString());
// 6401
// 233

[Link]("id")
employee["@id"]
employee.@["id"]

employee.@id employee.@id

( )

XML
var x:XML =
<employeeList>
<employee id="347">
<lastName>Zmed</lastName>
<firstName>Sue</firstName>
<position>Data analyst</position>
</employee>
<employee id="348">
<lastName>McGee</lastName>
<firstName>Chuck</firstName>
<position>Jr. data analyst</position>
</employee>
</employeeList>

308

XML

[Link].(lastName == "McGee") employee

[Link].(lastName == "McGee").firstName employee


firstName

[Link].(lastName == "McGee".@id employee id

[Link].(@id == 347) employee

[Link].(@id == 347).lastName employee lastName

[Link].(@id > 300) employee

[Link].([Link]().search("analyst") > -1)


position

XMLList

XMLList

Adobe Flash Player


p id
var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(@id == '123'));

p b
var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(b == 'Bob'));

attribute() elements()

var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(attribute('id') == '123'));
trace(doc.p.(elements('b') == 'Bob'));

XML

309

hasOwnProperty()
var doc:XML =
<body>
<p id='123'>Hello, <b>Bob</b>.</p>
<p>Hello.</p>
</body>;
trace(doc.p.(hasOwnProperty('@id') && @id == '123'));
trace(doc.p.(hasOwnProperty('b') && b == 'Bob'));

for..in for each..in


ActionScript 3.0 XMLList for..in for each..in
XML myXML XMLList [Link] XMLList
[Link] XML item
var myXML:XML =
<order>
<item id='1' quantity='2'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<item id='2' quantity='2'>
<menuName>fries</menuName>
<price>1.45</price>
</item>
</order>;
for..in

XMLList

var total:Number = 0;
for (var pname:String in [Link])
{
total += [Link].@quantity[pname] * [Link][pname];
}
for each..in

XMLList

var total2:Number = 0;
for each (var prop:XML in [Link])
{
total2 += prop.@quantity * [Link];
}

310

XML

XML
XML XML
SOAP Web XML

var message:XML =
<soap:Envelope xmlns:soap="[Link]
soap:encodingStyle="[Link]
<soap:Body xmlns:w="[Link]
<w:getWeatherResponse>
<w:tempurature >78</w:tempurature>
</w:getWeatherResponse>
</soap:Body>
</soap:Envelope>;

soap

URI [Link]

soap/envelope/

ActionScript 3.0 XML XML

var soapNS:Namespace = [Link]("soap");


trace(soapNS); // [Link]
var wNS:Namespace = new Namespace("w", "[Link]
[Link](wNS);
var encodingStyle:XMLList = message.@soapNS::encodingStyle;
var body:XMLList = [Link]::Body;
[Link]::[Link]::[Link]::tempurature = "78";

XML addNamespace() inScopeNamespaces()


localName()name()namespace()namespaceDeclarations()removeNamespace()
setLocalName() setName() setNamespace()
default xml namespace XML
x1 x2
var ns1:Namespace = new Namespace("[Link]
default xml namespace = ns1;
var x1:XML = <test1 />;
var x2:XML = <test2 />;

XML

311

XML
XML XMLList XML
XMLList XML
XML

XML XMLList
XML XMLList toString() toXMLString()
toXMLString() XML
XML toString() toXMLString()
XML toString()

var myXML:XML =
<order>
<item id='1' quantity='2'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<order>;
trace([Link][0].[Link]());
// <menuName>burger</menuName>
trace([Link][0].[Link]());
// burger

trace() toString() toXMLString()


toString()
var myXML:XML =
<order>
<item id='1' quantity='2'>
<menuName>burger</menuName>
<price>3.95</price>
</item>
<order>;
trace([Link][0].menuName);
// burger

trace() toXMLString() trace()

312

XML

XML
new XML()

XML

var x:XML = new XML("<a>test</a>");

XML

XML XML

var x:XML = new XML("<a>test"); //

XML String
Number()
var myXML:XML =
<order>
<item>
<price>3.95</price>
</item>
<item>
<price>1.00</price>
</item>
</order>;
var total:XML = <total>0</total>;
[Link](total);
for each (var item:XML in [Link])
{
[Link]()[0] = Number([Link]()[0])
+ Number([Link]()[0]);
}
trace([Link]); // 4.35;

Number() +
trace()
01.003.95

XML

313

XML
URLLoader URL XML
XML_URL URL
var myXML:XML = new XML();
var XML_URL:String = "[Link]
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
[Link]("complete", xmlLoaded);
function xmlLoaded(event:Event):void
{
myXML = XML([Link]);
trace("Data loaded.");
}

XMLSocket
ActionScript 3.0

XML

Internet RSS
RSSViewer ActionScript XML

XML RSS XML

XML HTML XML


RSS XML RSS
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="[Link]
<channel>
<title>Alaska - Weather</title>
<link>[Link]
<description>Alaska - Watches, Warnings and Advisories</description>
<item>
<title>
Short Term Forecast - Taiya Inlet, Klondike Highway (Alaska)
</title>
<link>
[Link]
</link>
<description>
Short Term Forecast Issued At: 2005-04-11T[Link]
Expired At: 2005-04-12T[Link] Issuing Weather Forecast Office
Homepage: [Link]
</description>
</item>
<item>

314

XML

<title>
Short Term Forecast - Haines Borough (Alaska)
</title>
<link>
[Link]
</link>
<description>
Short Term Forecast Issued At: 2005-04-11T[Link]
Expired At: 2005-04-12T[Link] Issuing Weather Forecast Office
Homepage: [Link]
</description>
</item>
</channel>
</rss>

SimpleRSS Internet RSS


SimpleRSSUI SimpleRSS
XML

[Link]/go/learn_programmingAS3samples_flash_cnRSSViewer
Samples/RSSViewer

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/rssViewer/
[Link]

E4X RSS
(XML) HTML

RSSData/[Link]

RSS Web
Adobe Flex RSS RSS

RSS Flex
RSS

XML
RSSParser xmlLoaded() RSS rssXML
HTML (rssOutput)

RSS XML

if ([Link]("") != undefined)
{
default xml namespace = [Link]("");
}

Internet RSS

315

XML item
for each (var item:XML in rssXML..item)
{
var itemTitle:String = [Link]();
var itemDescription:String = [Link]();
var itemLink:String = [Link]();
outXML += buildItemHTML(itemTitle,
itemDescription,
itemLink);
}

XML item
buildItemHTML() XMLList HTML

XMLList
HTML XMLList
<b>itemTitle</b>
<p>
itemDescription
<br />
<a href="link">
<font color="#008000">More...</font>
</a>
</p>

XML
default xml namespace = new Namespace();
default xml namespace
buildItemHTML()

XMLList
var body:XMLList = new XMLList();
body += new XML("<b>" + itemTitle + "</b>");
var p:XML = new XML("<p>" + itemDescription + "</p>");
var link:XML = <a></a>;
link.@href = itemLink; // <link href="itemLinkString"></link>
[Link].@color = "#008000";
// <font color="#008000"></font></a>
// 0x008000 = green
[Link] = "More...";
[Link](<br/>);
[Link](link);
body += p;

316

XML

XMLList ActionScript HTML


xmlLoaded() buildItemHTML()
[Link] = false;
rssOutput = [Link]();

RSS
xmlLoaded()

RSS XML rssTitle

rssTitle = [Link]();

xmlLoaded()
dataWritten = new Event("dataWritten", true);

Internet RSS

317

318

XML

12

12

ActionScript 3.0 Adobe Flash Player 9

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .324
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .326
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .339
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .356
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .358
SpriteArranger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .363

319

ActionScript 3.0

Stage

Stage

SWF

SWF ActionScript SWF Flash


Player HTML SWF Flash Player
Stage SWF
Sprite 326

320

DisplayObject stage
334

ActionScript 3.0
[Link] DisplayObject

326

DisplayObjectContainer DisplayObject DisplayObjectContainer


Sprite
DisplayObjectContainer
SimpleButton

Bitmap Bitmap
Loader
JPEG

Shape
ActionScript
Shape
Drop Shadow

TextField

DisplayObjectContainer

DisplayObject DisplayObject
Shape Video DisplayObject

321


ActionScript

SWF

ActionScript 387 14 API

371 13

403 15

425 16

TextField 439 17

465 18

477 19

322

Alpha Alpha
60% 60% 40%

(Bitmap graphic)

(Blending mode)

(Display list) Flash Player


(Display object) Flash Player


DisplayObject

(Display object container)

SWF (Main class of the SWF file) SWF


SWF Flash
SWF SWF

(Masking)

(Stage)

(Transformation)

(Vector graphic)

SWF

323

Flash Player

Flash

1.

2.
3.
4. >

trace()
53

ActionScript 3.0 [Link] Flash Player

DisplayObject

AVM1Movie

Bitmap

DisplayObjectContainer

Loader

Sprite

InteractiveObject

MorphShape

SimpleButton

TextField

Shape

StaticText

Video

Stage

MovieClip

StaticText TextField
Video [Link] DisplayObject
DisplayObject 328
DisplayObject

324

[Link]

Bitmap Bitmap ActionScript


Loader GIF JPG PNG
BitmapData Bitmap
BitmapData ActionScript
360 465 18

Loader Loader SWF


360

Shape Shape
387 14 API

SimpleButton SimpleButton Flash ActionScript


SimpleButton 3

Sprite Sprite Sprite


DisplayObjectContainer 329
387 14 API

MovieClip MovieClip Flash ActionScript


MovieClip Sprite
425 16
[Link] DisplayObject

TextField [Link]
439 17

Video [Link]
477 19
[Link] DisplayObject

AVM1Movie AVM1Movie ActionScript 1.0 2.0


SWF
DisplayObjectContainer LoaderStageSprite MovieClip
DisplayObjectContainer 329
InteractiveObject InteractiveObject
SimpleButton TextField Video Loader Sprite Stage MovieClip
InteractiveObject 543
21
MorphShape Flash
ActionScript

325

Stage Stage DisplayObjectContainer Stage


Stage DisplayObject
stage 334

[Link] StaticText DisplayObject


Adobe Flash CS3 Professional

ActionScript 3.0 ActionScript 1.0


MovieClip

2.0

ActionScript 1.0 2.0 MovieClip ActionScript 3.0


ActionScript 3.0
MovieClip

MovieClip Shape
ActionScript 3.0
Shape MovieClip Shape Flash
Player MovieClip

ActionScript 1.0 2.0 getNextHighestDepth()

ActionScript 3.0

326

DisplayObjectContainer

ActionScript 3.0 DisplayObjectContainer

ActionScript 3.0
DisplayObjectContainer numChildren
0
(numChildren - 1) ActionScript 1.0 2.0
MovieClip
ActionScript 3.0
ActionScript 1.0 2.0
ActionScript 1.0 2.0
ActionScript 3.0

ActionScript 3.0 DisplayObjectContainer getChildByName()

ActionScript 1.0 2.0 Flash


ActionScript 3.0 ActionScript
Flash 333

ActionScript 3.0
DisplayObjectContainer addChild()
addChildAt()

327


ActionScript 1.0 2.0 SWF MovieClip
ActionScript 3.0 DisplayObject
Shape Bitmap ActionScript 3.0

ActionScript 2.0
MovieClip CustomCircle MovieClip
totalFrames ActionScript 3.0
Shape CustomCircle MovieClip
CustomCircle
import [Link].*;
private class CustomCircle extends Shape
{
var xPos:Number;
var yPos:Number;
var radius:Number;
var color:uint;
public function CustomCircle(xInput:Number,
yInput:Number,
rInput:Number,
colorInput:uint)
{
xPos = xInput;
yPos = yInput;
radius = rInput;
color = colorInput;
[Link](color);
[Link](xPos, yPos, radius);
}
}

ActionScript 3.0

DisplayObject
DisplayObject DisplayObject
x
y

328

DisplayObject DisplayObject
DisplayObject Sprite new

Shape Sprite ActionScript 3.0


DisplayObject

myText
TextField this

import [Link].*;
import [Link];
var myText:TextField = new TextField();
[Link] = "Buenos dias.";
[Link](myText);

Stage
SWF HTML Stage
Sprite
ActionScript Adobe Flex Builder 2
MXML Flash
ActionScript ActionScript
ActionScript button1

[Link] = 200;

DisplayObjectContainer
DisplayObjectContainer

329


pictureScreen
PictureFrame

pictureScreen

pictureScreen

addChild() addChildAt()
myTextField
var myTextField:TextField = new TextField();
[Link] = "hello";
[Link](myTextField);

[Link] MovieClip

addChildAt()
0
Ball

330

addChildAt()

ball_A = new Ball(0xFFCC00, "a");


ball_A.name = "ball_A";
ball_A.x = 20;
ball_A.y = 20;
[Link](ball_A);
ball_B = new Ball(0xFFCC00, "b");
ball_B.name = "ball_B";
ball_B.x = 70;
ball_B.y = 20;
[Link](ball_B);
ball_C = new Ball(0xFFCC00, "c");
ball_C.name = "ball_C";
ball_C.x = 40;
ball_C.y = 60;
[Link](ball_C, 1);

container

DisplayObjectContainer

ball_A
[Link](ball_A);

ball_A container

getChildAt() getChildAt()
container
DisplayObjectContainer
trace([Link](0).name); // ball_A
trace([Link](1).name); // ball_C
trace([Link](2).name); // ball_B

331

container DisplayObjectContainer 2
1
[Link](ball_C);
trace([Link](0).name); // ball_A
trace([Link](1).name); // ball_B
removeChild() removeChildAt()
delete

tf1 Sprite
DisplayObjectContainer
tf1:TextField = new TextField();
tf2:TextField = new TextField();
[Link] = "text 1";
[Link] = "text 2";
container1:Sprite = new Sprite();
container2:Sprite = new Sprite();
[Link](tf1);
[Link](tf2);
[Link](tf1);
trace([Link]); // 1
trace([Link](0).name); // 2
trace([Link]); // 1
trace([Link](0).name); // 1

DisplayObjectContainer

contains()

DisplayObjectContainer

getChildByName()

getChildIndex()

setChildIndex()

swapChildren()

swapChildrenAt()

ActionScript 3.0

332

Stage

SWF

DisplayObjectContainer
container Sprite Sprite
DisplayObjectContainer title pict
var container:Sprite = new Sprite();
var title:TextField = new TextField();
[Link] = "Hello";
var pict:Loader = new Loader();
var url:URLRequest = new URLRequest("[Link]");
[Link](url);
[Link] = "banana loader";

333

[Link](title);
[Link](pict);
getChildAt()
trace([Link](0) is TextField); // true

Flash Player "instance1"


getChildByName() "banana loader"
trace([Link]("banana loader") is Loader); // true

getChildAt() getChildByName()

pict Loader
pict
[Link](0) [Link](0).getChildAt(0)
[Link](0) == pict
trace()
function traceDisplayList(container:DisplayObjectContainer,
indentString:String = ""):void
{
var child:DisplayObject;
for (var i:uint=0; i < [Link]; i++)
{
child = [Link](i);
trace(indentString, child, [Link]);
if ([Link](i) is DisplayObjectContainer)
{
traceDisplayList(DisplayObjectContainer(child), indentString + "")
}
}
}

Stage DisplayObject
Flash Player Stage x y
x y

334

SWF Stage
670 Stage


Stage framerate SWF
ActionScript 3.0

Flash Player Flash Player Stage


scaleMode
[Link]
scaleMode StageScaleMode.EXACT_FIT StageScaleMode.SHOW_ALL
StageScaleMode.NO_BORDER Flash Player

StageScaleMode.EXACT_FIT

StageScaleMode.SHOW_ALL

SWF

StageScaleMode.NO_BORDER

scaleMode StageScaleMode.NO_SCALE Flash Player


Stage width height
Flash Player
stageWidth stageHeight SWF
scaleMode StageScaleMode.NO_SCALE SWF Stage
resize
scaleMode StageScaleMode.NO_SCALE
SWF

// videoScreen
//
// SWF
//
//
//
//

controlBar Sprite
videoScreen
SWF

import
import
import
import

[Link];
[Link];
[Link];
[Link];

var swfStage:Stage = [Link];

335

[Link] = StageScaleMode.NO_SCALE;
[Link] = StageAlign.TOP_LEFT;
function resizeDisplay(event:Event):void
{
var swfWidth:int = [Link];
var swfHeight:int = [Link];
// Resize the video window.
var newVideoHeight:Number = swfHeight - [Link];
[Link] = newVideoHeight;
[Link] = [Link];
// Reposition the control bar.
controlBar.y = newVideoHeight;
}
[Link]([Link], resizeDisplay);

SWF Stage
displayState SWF displayState
[Link]
displayState StageDisplayState.FULL_SCREEN
// mySprite Sprite
[Link] = StageDisplayState.FULL_SCREEN;

displayState [Link]
[Link] = [Link];

Esc Ctrl-W (Windows) Command-W (Mac) Alt-F4 (Windows)


Stage scaleMode
scaleMode StageScaleMode.NO_SCALE Stage stageWidth
stageHeight SWF

Stage fullScreen

import [Link];
function fullScreenRedraw(event:FullScreenEvent):void
{
if ([Link])
{
//

336

//
}
else
{
//
//
}
}
[Link](FullScreenEvent.FULL_SCREEN,
fullScreenRedraw);

fullScreen [Link]
(true) (false) fullScreen
ActionScript

ActionScript

SWF Flash Player


SWF

HTML SWF Flash Player HTML

allowFullScreen true param embed


<object>
...
<param name="allowFullScreen" value="true" />
<embed ... allowfullscreen="true" />
</object>

JavaScript SWF JavaScript


allowFullScreen param HTML AC_FL_RunContent()
Flex Builder Flash HTML
allowFullScreen
AC_FL_RunContent(
...
'allowFullScreen','true',
...
); //end AC code

Flash Player

SWF
ActionScript TextField

660

337


DisplayObject EventDispatcher
267 10
addEventListener() EventDispatcher

Flash Player
1 Flash Player
1

267 10

283

DisplayObject

338

DisplayObject InteractiveObject

Bitmap

TextField

Video

Shape
Shape Sprite
MovieClip
Flash MorphShape StaticText SimpleButton
Flash

Stage

SWF Loader
Loader

Bitmap
ActionScript 3.0 SWF

Sprite MovieClip

ActionScript 1.0 ActionScript 2.0 SWF


AVM1Movie
ActionScript
DisplayObjectContainer

ActionScript ActionScript
Sprite

Flash
MovieClip
Flash
DisplayObjectContainer

MovieClip

Sprite

(DisplayObject)
TextField Video Shape

339

x y
myShape.x = 17;
myShape.y = 212;

x y
x y 0,0 x
y
myShape x 17 17 y
212 212
ActionScript x y 0

x y 0,0
Sprite Shape Shape
x y 0 Sprite
globalToLocal()

//
//
// Sprite x200 y200
var mySprite:Sprite = new Sprite();
mySprite.x = 200;
mySprite.y = 200;
[Link](mySprite);
// Sprite 0,0
[Link](1, 0x000000);
[Link](0x000000);
[Link](0, 0);
[Link](1, 0);
[Link](1, 1);
[Link](0, 1);
[Link]();
// Shape
var circle:Shape = new Shape();
[Link](circle);
// Shape 50 x y 50

340

[Link](1, 0x000000);
[Link](0xff0000);
[Link](50, 50, 50);
[Link]();
// Shape 0, 0
var stagePoint:Point = new Point(0, 0);
var targetPoint:Point = [Link](stagePoint);
circle.x = targetPoint.x;
circle.y = targetPoint.y;

DisplayObject localToGlobal()

ActionScript

startDrag()
startDrag() stopDrag()
// startDrag()
//
// DisplayObject MovieClip Sprite
import [Link];
//
function startDragging(event:MouseEvent):void
{
[Link]();
}
//
function stopDragging(event:MouseEvent):void
{
[Link]();
}
[Link](MouseEvent.MOUSE_DOWN, startDragging);
[Link](MouseEvent.MOUSE_UP, stopDragging);

341

startDrag()
startDrag()
startDragging() circle
[Link]()
function startDragging(event:MouseEvent):void
{
[Link]();
[Link]();
}

startDrag() stopDrag()

startDrag()

mouseMove
x,y

//
//
// DisplayObject MovieClip Sprite
import [Link];
var offsetX:Number;
var offsetY:Number;
//
function startDragging(event:MouseEvent):void
{
//
// x, y
//
offsetX = [Link] - circle.x;
offsetY = [Link] - circle.y;
// Flash Player mouseMove
[Link](MouseEvent.MOUSE_MOVE, dragCircle);
}
//
function stopDragging(event:MouseEvent):void
{
// Flash Player mouseMove
[Link](MouseEvent.MOUSE_MOVE, dragCircle);
}

342

//
//
function dragCircle(event:MouseEvent):void
{
//
//
//
circle.x = [Link] - offsetX;
circle.y = [Link] - offsetY;
// Flash Player
[Link]();
}
[Link](MouseEvent.MOUSE_DOWN, startDragging);
[Link](MouseEvent.MOUSE_UP, stopDragging);

//
//
//
//

DisplayObject MovieClip Sprite

import [Link];
import [Link];
var offsetX:Number;
var offsetY:Number;
var draggedObject:DisplayObject;
//
function startDragging(event:MouseEvent):void
{
//
draggedObject = DisplayObject([Link]);
//
// x, y
//

343

offsetX = [Link] - draggedObject.x;


offsetY = [Link] - draggedObject.y;
//
[Link](draggedObject);
// Flash Player mouseMove
[Link](MouseEvent.MOUSE_MOVE, dragObject);
}
//
function stopDragging(event:MouseEvent):void
{
// Flash Player mouseMove
[Link](MouseEvent.MOUSE_MOVE, dragObject);
}
//
//
function dragObject(event:MouseEvent):void
{
//
//
//
draggedObject.x = [Link] - offsetX;
draggedObject.y = [Link] - offsetY;
// Flash Player
[Link]();
}
[Link](MouseEvent.MOUSE_DOWN, startDragging);
[Link](MouseEvent.MOUSE_UP, stopDragging);
[Link](MouseEvent.MOUSE_DOWN, startDragging);
[Link](MouseEvent.MOUSE_UP, stopDragging);


ActionScript
403 15

344


scrollRect
scrollRect

scrollRect

Rectangle Rectangle
Rectangle
scrollRect scrollRect
Rectangle Rectangle x
y Rectangle scrollRect

bigText TextField
SWF up down
scrollRect Rectangle y TextField
import [Link];
import [Link];
// TextField
// 00TextField 350
[Link] = new Rectangle(0, 0, [Link], 350);
// TextField
[Link] = true;
//
function scrollUp(event:MouseEvent):void
{
//
var rect:Rectangle = [Link];
// y 20
// 20
rect.y -= 20;
// TextField
[Link] = rect;
}
//
function scrollDown(event:MouseEvent):void
{
//
var rect:Rectangle = [Link];
// y 20
// 20
rect.y += 20;
// TextField
[Link] = rect;
}

345

[Link]([Link], scrollUp);
[Link]([Link], scrollDown);

scrollRect Flash Player


cacheAsBitmap
Flash Player
349

width height
scaleX scaleY
width height

//
[Link] = 420;
[Link] = 420;
//
var radius:Number = [Link] / 2;

height width

width height Flash Player scaleX


scaleY scaleX scaleY
width
scaleX .5 50
scaleY 2 200
// 150
// scaleX scaleY 1 (100%)
trace([Link]);// 1
trace([Link]);// 1
// width height
// Flash Player scaleX scaleY
[Link] = 100;
[Link] = 75;
trace([Link]);// 0.6622516556291391
trace([Link]);// 0.4966887417218543

346

height width

scaleX scaleY
width height square width
(scaleY)
//
[Link] = 150;
//
//
[Link] = [Link];

347

9 (Scale-9) 9
9 3 x 3

ActionScript scale9Grid 9
Scale-9 Rectangle
scale9Grid
myButton.scale9Grid = new Rectangle(32, 27, 71, 64);

Rectangle x y width height


myButton x32 y27 71 65
x 103 y
92

Rectangle Scale-9
Flash Player Rectangle

348


[Link] = 131;
[Link] = 106;
[Link] = 73;
[Link] = 69;
[Link] = 54;
[Link] = 141;

Flash
Shape Flash
Flash Shape
SWF
SWF
SWF SWF

SWF

cacheAsBitmap true
Flash surface

351

DisplayObject opaqueBackground scrollRect cacheAsBitmap



opaqueBackground scrollRect cacheAsBitmap true
opaqueBackground scrollRect
345
351
Alpha cacheAsBitmap true
Alpha

357

349

SWF

opaqueBackground


Adobe Illustrator

opaqueBackground true

scrollRect
Flash

Web cacheAsBitmap
true

Alpha Alpha cacheAsBitmap true


357 Alpha

Flash Player cacheAsBitmap true


false cacheAsBitmap

350


SWF

Sprite
250 x 250 250 KB
Sprite 1 KB



MovieClip Video
SWF

Flash Player

cacheAsBitmap true
[Link] = true;

cacheAsBitmap true
SWF

cacheAsBitmap true

2880

SWF
opaqueBackground

cacheAsBitmap true opaqueBackground
opaqueBackground cacheAsBitmap
trueopaqueBackground

351


[Link] = true;
[Link] = 0xFF0000;

myShape Shape (0xFF0000) Shape


Shape Shape

SWF opaqueBackground 0xFFFFFF

blendMode BlendMode
String

[Link] ("add")

[Link] ("alpha")

[Link] ("darken")

[Link] ("difference")

[Link] ("erase")

[Link] ("hardlight")

[Link] ("invert")

[Link] ("layer")

[Link] ("lighten")

[Link] ("multiply")

[Link] ("normal")

[Link] ("overlay")

[Link] ("screen")

[Link] ("subtract")

352

Alpha

DisplayObject
ColorTransform ([Link])
transform Transform

Transform colorTransform ColorTransform

var colorInfo:ColorTransform = [Link];

ColorTransform

ColorTransform [Link]
var colorInfo:ColorTransform = my [Link];
//
//
[Link] = colorInfo;

ColorTransform color (RGB)


blueBtn color square

// square
// blueBtn redBtn greenBtn blackBtn
import [Link];
import [Link];
// square ColorTransform
var colorInfo:ColorTransform = [Link];
// blueBtn
function makeBlue(event:MouseEvent):void
{
// ColorTransform
[Link] = 0x003399;
//
[Link] = colorInfo;
}
[Link]([Link], makeBlue);

353

color

ColorTransform color


ColorTransform
redMultipliergreenMultiplier
blueMultiplier alphaMultiplier
redOffsetgreenOffsetblueOffset
alphaOffset

Flash

JPEG x y

import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];

//
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("[Link]
images/[Link]");
[Link](url);
[Link](loader);
//
function adjustColor(event:MouseEvent):void
{
// Loader ColorTransform
var colorTransformer:ColorTransform = [Link];
//
//
//
//
//

354

0%
100%

[Link] = ([Link] / [Link]) * 1;


[Link] = ([Link] / [Link]) * 1;
//
[Link] = colorTransformer;
}
[Link](MouseEvent.MOUSE_MOVE, adjustColor);

rotation

square 45 1/8
[Link] = 45;

371 13


DisplayObject alpha
alpha 0 1 0
1 myBall
(50)
function fadeBall(event:MouseEvent):void
{
[Link] = .5;
}
[Link]([Link], fadeBall);

ColorTransform
353 DisplayObject

355

mask
// maskSprite mySprite
[Link] = maskSprite;

100 x 100 Shape 25


Sprite

//
// MovieClip Sprite
import [Link];
//
var square:Shape = new Shape();
[Link](1, 0x000000);
[Link](0xff0000);
[Link](0, 0, 100, 100);
[Link]();
[Link](square);
//
var circle:Sprite = new Sprite();
[Link](1, 0x000000);
[Link](0x0000ff);
[Link](25, 25, 25);
[Link]();
[Link](circle);
function maskSquare(event:MouseEvent):void
{
[Link] = circle;
[Link]([Link], maskSquare);
}
[Link]([Link], maskSquare);

356

MovieClip
mask null
// mySprite
[Link] = null;

alpha

SWF

Alpha

Alpha

// maskShape Shape
[Link] = true;
[Link] = true;
[Link] = maskShape;

Alpha

Loader
Alpha

//
// MovieClip Sprite
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];

357

//
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("[Link]
images/[Link]");
[Link](url);
[Link](loader);
// Sprite
var oval:Sprite = new Sprite();
//
var colors:Array = [0x000000, 0x000000];
var alphas:Array = [1, 0];
var ratios:Array = [0, 255];
var matrix:Matrix = new Matrix();
[Link](200, 100, 0, -100, -50);
[Link]([Link],
colors,
alphas,
ratios,
matrix);
[Link](-100, -50, 200, 100);
[Link]();
// Sprite
[Link](oval);
// cacheAsBitmap = true
[Link] = true;
[Link] = true;
//
[Link] = oval;
//
[Link](true);

ActionScript
ActionScript

ActionScript

358

SWF
Flash Player
enterFrame SWF
enterFrame
enterFrame

Timer Timer
Timer timer
Timer 164

circle Sprite
circle alpha
import [Link];
import [Link];
import [Link];
//
var circle:Sprite = new Sprite();
[Link](0x990000);
[Link](50, 50, 50);
[Link]();
addChild(circle);
//
//
//
function fadeCircle(event:Event):void
{
[Link] -= .05;
if ([Link] <= 0)
{
[Link](Event.ENTER_FRAME, fadeCircle);
}
}
function startAnimation(event:MouseEvent):void
{
[Link](Event.ENTER_FRAME, fadeCircle);
}
[Link]([Link], startAnimation);

359

fadeCircle() enterFrame
circle alpha
alpha .05 5% alpha 0circle
fadeCircle()
enterFrame
alpha
[Link] -= .05;

circle.x += 5;

x
enterFrame

ActionScript 3.0

ActionScript 3.0 SWF Sprite MovieClip


Sprite

JPG PNG GIF

AVM1 SWF ActionScript 1.0 2.0 SWF


Loader

Loader SWF Loader


DisplayObjectContainer Loader
SWF
Loader
var pictLdr:Loader = new Loader();
var pictURL:String = "[Link]"
var pictURLReq:URLRequest = new URLRequest(pictURL);
[Link](pictURLReq);
[Link](pictLdr);

SWF
container DisplayObjectContainer
import [Link].*;
import [Link];
import [Link];
var container:Sprite = new Sprite();

360

addChild(container);
var pictLdr:Loader = new Loader();
var pictURL:String = "[Link]"
var pictURLReq:URLRequest = new URLRequest(pictURL);
[Link](pictURLReq);
[Link]([Link], imgLoaded);
function imgLoaded(event:Event):void
{
[Link]([Link]);
}

LoaderInfo LoaderInfo
URLLoaderInfo

LoaderInfo SWF Loader


Loader

LoaderInfo
loaderInfo

SWF

Loader

LoaderInfo

LoaderInfo

loaderInfo

LoaderInfo Loader
Loader contentLoaderInfo LoaderInfo
LoaderInfo loaderInfo
loaderInfo Loader contentLoaderInfo
LoaderInfo LoaderInfo Loader

361

LoaderInfo
import [Link];
import [Link];
import [Link];
var ldr:Loader = new Loader();
var urlReq:URLRequest = new URLRequest("[Link]");
[Link](urlReq);
[Link]([Link], loaded);
addChild(ldr);
function loaded(event:Event):void
{
var content:Sprite = [Link];
[Link] = 2;
}

267 10

Loader load() loadBytes() Flash Player


context LoaderContext

LoaderContext

checkPolicyFile SWF
trueLoader 656 Web
Loader SWF
Loader Loader SWF
ActionScript [Link]()

Loader SWF
[Link]()

securityDomain

SWF SWF

Loader
Flash Player
SWF SWF
[Link]

362

applicationDomain

ActionScript 3.0 SWF


ActionScript 1.0 2.0 SWF
applicationDomain [Link]
Loader SWF
SWF

603 ApplicationDomain

var context:LoaderContext = new LoaderContext();


[Link] = true;
var urlReq:URLRequest = new URLRequest("[Link]
[Link]");
var ldr:Loader = new Loader();
[Link](urlReq, context);

SWF Loader
SWF Loader

var context:LoaderContext = new LoaderContext();


[Link] = [Link];
[Link] = [Link];
var urlReq:URLRequest = new URLRequest("[Link]
[Link]");
var ldr:Loader = new Loader();
[Link](urlReq, context);

ActionScript 3.0

LoaderContext

SpriteArranger
SpriteArranger GeometricShapes
149 GeometricShapes
SpriteArranger

SpriteArranger

363

[Link]/go/learn_programmingAS3samples_flash_cn
Examples/SpriteArranger SpriteArranger

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/
SpriteArranger/[Link]

Sprite

com/example/programmingas3/
SpriteArranger/[Link]

GeometricSprite

com/example/programmingas3/
SpriteArranger/[Link]

Sprite

com/example/programmingas3/
SpriteArranger/[Link]

Sprite

com/example/programmingas3/
SpriteArranger/[Link]

Sprite
CircleSprite SquareSprite TriangleSprite

com/example/programmingas3/
geometricshapes/[Link]

com/example/programmingas3/
geometricshapes/[Link]

com/example/programmingas3/
geometricshapes/[Link]

com/example/programmingas3/
geometricshapes/[Link]

com/example/programmingas3/
geometricshapes/[Link]

RegularPolygon

com/example/programmingas3/
geometricshapes/[Link]

RegularPolygon

com/example/programmingas3/
geometricshapes/
[Link]

364

SpriteArranger
SpriteArranger

DrawingCanvas
GeometricSprite

DrawingCanvas
DrawingCanvas Sprite DrawingCanvas

public class DrawingCanvas extends Sprite

Sprite DisplayObjectContainer DisplayObject DrawingCanvas

DrawingCanvas()

Rectangle bounds
initCanvas()

[Link] = new Rectangle(0, 0, w, h);


initCanvas(fillColor, lineColor);

initCanvas()

DrawingCanvas

[Link] = lineColor;
[Link] = fillColor;
[Link] = 500;
[Link] = 200;
initCanvas() drawBounds()

DrawingCanvas graphics

graphics Shape
[Link]();
[Link](1.0, [Link], 1.0);
[Link]([Link], 1.0);
[Link]([Link] - 1,
[Link] - 1,
[Link] + 2,
[Link] + 2);
[Link]();

DrawingCanvas

addShape() describeChildren() 366

moveToBack()moveDown()moveToFront() moveUp() 369

onMouseUp() 368

SpriteArranger

365

GeometricSprite
GeometricSprite

CircleSprite
SquareSprite
TriangleSprite

GeometricSprite [Link]
public class GeometricSprite extends Sprite

GeometricSprite GeometricSprite

[Link] = size;
[Link] = lColor;
[Link] = fColor;

GeometricSprite geometricShape IGeometricShape


IGeometricShape
GeometricShapes 149
GeometricShapes
GeometricSprite drawShape() GeometricSprite

GeometricSprite

onMouseDown() onMouseUp() 368


showSelected() hideSelected() 368

DrawingCanvas addShape()
GeometricSprite GeometricSprite

public function addShape(shapeName:String, len:Number):void


{
var newShape:GeometricSprite;
switch (shapeName)
{
case "Triangle":
newShape = new TriangleSprite(len);
break;
case "Square":
newShape = new SquareSprite(len);

366

break;
case "Circle":
newShape = new CircleSprite(len);
break;
}
[Link] = 0.8;
[Link](newShape);
}

drawShape() Sprite graphics


CircleSprite drawShape()
[Link]();
[Link](1.0, [Link], 1.0);
[Link]([Link], 1.0);
var radius:Number = [Link] / 2;
[Link](radius, radius, radius);
addShape()

DisplayObject alpha

addChild() DrawingCanvas

selectedSpriteTxt outputTxt
GeometricSprite GeometricSprite
toString()
public override function toString():String
{
return [Link] + of size + [Link] + " at " + this.x + ", " +
this.y;
}
shapeType

GeometricSprite

toString() DrawingCanvas CircleSprite


Circle of size 50 at 0, 0

DrawingCanvas describeChildren() numChildren


DisplayObjectContainer for

var desc:String = "";


var child:DisplayObject;
for (var i:int=0; i < [Link]; i++)
{
child = [Link](i);
desc += i + ": " + child + '\n';
}

outputTxt text

SpriteArranger

367


GeometricSprite onMouseDown()
GeometricSprite
[Link](MouseEvent.MOUSE_DOWN, onMouseDown);
onMouseDown()

GeometricSprite showSelected()
selectionIndicator Shape
Shape graphics
[Link] = new Shape();
[Link](1.0, 0xFF0000, 1.0);
[Link](-1, -1, [Link] + 1,
[Link] + 1);
[Link]([Link]);

onMouseDown() selectionIndicator
visible DisplayObject
[Link] = true;
hideSelected() visible false
selectionIndicator
onMouseDown() startDrag()

Sprite

var boundsRect:Rectangle = [Link]([Link]);


[Link] -= [Link];
[Link] -= [Link];
[Link](false, boundsRect);

boundsRect
mouseUp DrawingCanvas

[Link](MouseEvent.MOUSE_UP, onMouseUp);

DrawingCanvas GeometricSprite
GeometricSprite
GeometricSprite
DrawingCanvas

onMouseUp()

GeometricSprite onMouseUp()
GeometricSprite stopDrag()

368



DrawingCanvas moveToBack()
moveDown() moveUp() moveToFront() moveToBack()
public function moveToBack(shape:GeometricSprite):void
{
var index:int = [Link](shape);
if (index > 0)
{
[Link](shape, 0);
}
}

setChildIndex() DisplayObjectContainer
DrawingCanvas (this) 0
moveDown()
1

DrawingCanvas

public function moveDown(shape:GeometricSprite):void


{
var index:int = [Link](shape);
if (index > 0)
{
[Link](shape, index - 1);
}
}
moveUp() moveToFront() moveToBack() moveDown()

SpriteArranger

369

370

13

13

[Link]

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381

ActionScript

[Link]

(x) (y) x y

371


x y 0, 0

x x
ActionScript y
y
x 0 y 0
Point Rectangle
Matrix

339

ActionScript

Rectangle

Rectangle

Rectangle

Rectangle

Matrix

Matrix

372

(Cartesian coordinate) 5, 12 17,


-23 x y
(Coordinate space)
(Origin) x y 0, 0
(Point) ActionScript
x y
(Registration point) 0, 0

(Scale)

(Translate)

(Transformation)

X (X axis)ActionScript
Y (Y axis)ActionScript

trace()

1.

Flash

2.
3.
4. >

trace

1.

Flash

2.
3.
4. >

5.


myDisplayObject myDisplayObject
6. >

53

373

Point
Point x y

Point x y
import [Link].*;
var pt1:Point = new Point(10, 20); // x == 10; y == 20
var pt2:Point = new Point();
pt2.x = 10;
pt2.y = 20;

Point distance()
circle1 circle2
import [Link].*;
var pt1:Point = new Point(circle1.x, circle1.y);
var pt2:Point = new Point(circle2.x, circle2.y);
var distance:Number = [Link](pt1, pt2);

DisplayObject localToGlobal()
circle1 circle2

import [Link].*;
var pt1:Point = new Point(circle1.x, circle1.y);
pt1 = [Link](pt1);
var pt2:Point = new Point(circle1.x, circle1.y);
pt2 = [Link](pt2);
var distance:Number = [Link](pt1, pt2);

target
DisplayObject localToGlobal()
import [Link].*;
var stageCenter:Point = new Point();
stageCenter.x = [Link] / 2;
stageCenter.y = [Link] / 2;
var targetCenter:Point = new Point(target.x, target.y);
targetCenter = [Link](targetCenter);
var distance:Number = [Link](stageCenter, targetCenter);

374


Point polar()
60 myDisplayObject 100
import [Link].*;
var distance:Number = 100;
var angle:Number = 2 * [Link] * (90 / 360);
var translatePoint:Point = [Link](distance, angle);
myDisplayObject.x += translatePoint.x;
myDisplayObject.y += translatePoint.y;

Point
Point

DisplayObjectContainer

areInaccessibleObjectsUnderPoint()
getObjectsUnderPoint()

BitmapData

hitTest()

BitmapData

BitmapData

applyFilter()
copyChannel()
merge()
paletteMap()
pixelDissolve()
threshold()

Matrix

deltaTransformPoint()
transformPoint()

Rectangle

bottomRight
size
topLeft

Point

375

Rectangle
Rectangle Rectangle x
y width height Rectangle()

Rectangle
import [Link];
var rx:Number = 0;
var ry:Number = 0;
var rwidth:Number = 100;
var rheight:Number = 50;
var rect1:Rectangle = new Rectangle(rx, ry, rwidth, rheight);

Rectangle
Rectangle
Rectangle x y Rectangle

import [Link];
var x1:Number = 0;
var y1:Number = 0;
var width1:Number = 100;
var height1:Number = 50;
var rect1:Rectangle = new Rectangle(x1, y1, width1, height1);
trace(rect1) // (x=0, y=0, w=100, h=50)
rect1.x = 20;
rect1.y = 30;
trace(rect1); // (x=20, y=30, w=100, h=50)

Rectangle left top


x y left top Rectangle

import [Link];
var x1:Number = 0;
var y1:Number = 0;
var width1:Number = 100;
var height1:Number = 50;
var rect1:Rectangle = new Rectangle(x1, y1, width1, height1);
trace(rect1) // (x=0, y=0, w=100, h=50)
[Link] = 20;
[Link] = 30;
trace(rect1); // (x=30, y=20, w=70, h=30)

376

Rectangle bottom right

import [Link];
var x1:Number = 0;
var y1:Number = 0;
var width1:Number = 100;
var height1:Number = 50;
var rect1:Rectangle = new Rectangle(x1, y1, width1, height1);
trace(rect1) // (x=0, y=0, w=100, h=50)
[Link] = 60;
[Link] = 20;
trace(rect1); // (x=0, y=0, w=60, h=20)

offset() Rectangle
import [Link];
var x1:Number = 0;
var y1:Number = 0;
var width1:Number = 100;
var height1:Number = 50;
var rect1:Rectangle = new Rectangle(x1, y1, width1, height1);
trace(rect1) // (x=0, y=0, w=100, h=50)
[Link](20, 30);
trace(rect1); // (x=20, y=30, w=100, h=50)
offsetPt()

Point x y

inflate() Rectangle dx dy
dx dy

import [Link];
var x1:Number = 0;
var y1:Number = 0;
var width1:Number = 100;
var height1:Number = 50;
var rect1:Rectangle = new Rectangle(x1, y1, width1, height1);
trace(rect1) // (x=0, y=0, w=100, h=50)
[Link](6,4);
trace(rect1); // (x=-6, y=-4, w=112, h=58)
inflatePt()

Point dx dy

Rectangle

377

Rectangle
union()
import [Link].*;
import [Link];
var rect1:Rectangle = new Rectangle(0, 0, 100, 100);
trace(rect1); // (x=0, y=0, w=100, h=100)
var rect2:Rectangle = new Rectangle(120, 60, 100, 100);
trace(rect2); // (x=120, y=60, w=100, h=100)
trace([Link](rect2)); // (x=0, y=0, w=220, h=160)

intersection()
import [Link].*;
import [Link];
var rect1:Rectangle = new Rectangle(0, 0, 100, 100);
trace(rect1); // (x=0, y=0, w=100, h=100)
var rect2:Rectangle = new Rectangle(80, 60, 100, 100);
trace(rect2); // (x=120, y=60, w=100, h=100)
trace([Link](rect2)); // (x=80, y=60, w=20, h=40)

intersects() intersects()
circle
intersects()
circle target1 target2 Rectangle
import [Link].*;
import [Link];
var circle:Shape = new Shape();
[Link](2, 0xFF0000);
[Link](250, 250, 100);
addChild(circle);
var circleBounds:Rectangle = [Link](stage);
var target1:Rectangle = new Rectangle(0, 0, 100, 100);
trace([Link](target1)); // false
var target2:Rectangle = new Rectangle(0, 0, 300, 300);
trace([Link](target2)); // true

intersects()

DisplayObject getRect()

378

Rectangle
Rectangle

BitmapData

applyFilter() colorTransform()

copyChannel() copyPixels()
BitmapData
draw() fillRect()

generateFilterRect()
getColorBoundsRect() getPixels()
merge() paletteMap()
pixelDissolve() setPixels()
threshold()

DisplayObject

getBounds() getRect() scrollRect


scale9Grid

PrintJob

addPage()

printArea

Sprite

startDrag()

bounds

TextField

getCharBoundaries()

Transform

pixelBounds

Matrix
Matrix
Matrix Matrix
Transform matrix Transform transform
x y

Matrix
Matrix a b c d tx ty
createBox()
Matrix 2.0
3.0 45 10 20
var matrix:Matrix = new Matrix();
var scaleX:Number = 2.0;
var scaleY:Number = 3.0;
var rotation:Number = 2 * [Link] * (45 / 360);
var tx:Number = 10;
var ty:Number = 20;
[Link](scaleX, scaleY, rotation, tx, ty);

Matrix

379

scale() rotate() translate() Matrix


Matrix
scale() rotate() Matrix 4 60
var matrix:Matrix = new Matrix();
var rotation:Number = 2 * [Link] * (30 / 360); // 30
var scaleFactor:Number = 2;
[Link](scaleFactor, scaleFactor);
[Link](rotation);
[Link](scaleX, scaleY);
[Link](rotation);
[Link] = matrix;

Matrix b c b
c 2 myMatrix Matrix
var skewMatrix:Matrix = new Matrix();
skewMatrix.b = [Link](2);
[Link](skewMatrix);

transform
myDisplayObject
var matrix:Matrix = [Link];
var scaleFactor:Number = 2;
var rotation:Number = 2 * [Link] * (60 / 360); // 60
[Link](scaleFactor, scaleFactor);
[Link](rotation);
[Link] = matrix;

Matrix myDisplayObject
myDisplayObject transformation matrix
Matrix

380

ColorTransform [Link] Transform


colorTransform
ActionScript 3.0 ColorTransform


DisplayObjectTransformer Matrix

381

-45 50%

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/DisplayObjectTransformer DisplayObjectTransformer

[Link]

Flash (FLA) Flex (MXML)

[Link]
com/example/programmingas3/geometry/
[Link]

img/

MatrixTransformer
MatrixTransformer Matrix

transform()
transform()

sourceMatrix

xScale yScale

dx dy

rotation

382

x y

x y

skew

skewType "right" "left"

transform()

skew()

scale()

translate()

rotate()

skew()
skew() b c unit
angle
if (unit == "degrees")
{
angle = [Link] * 2 * angle / 360;
}
if (unit == "gradients")
{
angle = [Link] * 2 * angle / 100;
}

skewMatrix Matrix
var skewMatrix:Matrix = new Matrix();
skewSide "right" b

skewMatrix.b = [Link](angle);

c
skewMatrix.c = [Link](angle);

[Link](skewMatrix);
return sourceMatrix;

383

scale()
scale()
scale()
if (percent)
{
xScale = xScale / 100;
yScale = yScale / 100;
}
[Link](xScale, yScale);
return sourceMatrix;

translate()
translate() translate() dx dy

[Link](dx, dy)
sourceMatrix

rotate()
rotate()

rotate()
if (unit == "degrees")
{
angle = [Link] * 2 * angle / 360;
}
if (unit == "gradients")
{
angle = [Link] * 2 * angle / 100;
}
[Link](angle);
return sourceMatrix;

[Link]()

transform matrix [Link]()


tempMatrix = [Link](tempMatrix,
[Link],
[Link],
[Link],
[Link],
[Link],
[Link],
skewSide );

384

transform matrix

[Link] = tempMatrix;

385

386

14

14

API
API
ActionScript

API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .388
Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .389
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .392
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .393
Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .398
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Algorithmic Visual Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400

387

API
API
API ActionScript
ActionScript
[Link] Shape Sprite MovieClip
ActionScript graphics
graphics Graphics
Graphics

Graphics
Math

API

ActionScript API

API

API

(Anchor

point)
(Control point)

(Coordinate space)

(Fill)

388

API

(Gradient)

(Point)
x y

(Quadratic Bzier curve)


(Scale)

(Stroke)

(Translate)

X (X axis)ActionScript
Y (Y axis)ActionScript

ActionScript

SWF

1.

Flash

2.
3.
4. >

SWF

Graphics
ShapeSprite MovieClip graphics Graphics
Graphics
Shape Shape
Sprite MovieClip
Sprite
338 DisplayObject

Graphics

389


Graphics
ActionScript

Shape Sprite MovieClip graphics


Adobe Flash CS3 Professional
ActionScript

lineStyle() lineGradientStyle()
lineStyle()
Alpha myShape Shape 2
(0x990000) 75%
[Link](2, 0x990000, .75);

Alpha 1.0 (100%)


lineStyle()
ActionScript 3.0 [Link]()

lineGradientStyle() 393

beginFill() beginGradientFill()
beginBitmapFill() beginFill()

Alpha
myShape
[Link](0x00FF00);

390

API

Graphics

Graphics (0, 0)
moveTo()

lineTo() curveTo()

moveTo()

Adobe Flash Player endFill()


endFill()
endFill() Flash Player
moveTo()
endFill() beginFill()

lineTo() Graphics

(100, 100) (200, 200)


[Link](100, 100);
[Link](200, 200);

100
var triangleHeight:uint = 100;
var triangle:Shape = new Shape();
// red triangle, starting at point 0, 0
[Link](0xFF0000);
[Link](triangleHeight/2, 0);
[Link](triangleHeight, triangleHeight);
[Link](0, triangleHeight);
[Link](triangleHeight/2, 0);
// green triangle, starting at point 200, 0
[Link](0x00FF00);
[Link](200 + triangleHeight/2, 0);
[Link](200 + triangleHeight, triangleHeight);
[Link](200, triangleHeight);
[Link](200 + triangleHeight/2, 0);
[Link](triangle);

391


curveTo()

Graphics
curveTo() x y x y
(100, 100) (200, 200)
(175, 125)
[Link](100, 100);
[Link](175, 125, 200, 200);

100

var size:uint = 100;


var roundObject:Shape = new Shape();
// red circular shape
[Link](0xFF0000);
[Link](size / 2, 0);
[Link](size, 0, size, size / 2);
[Link](size, size, size / 2, size);
[Link](0, size, 0, size / 2);
[Link](0, 0, size / 2, 0);
// green circular shape
[Link](0x00FF00);
[Link](200 + size / 2, 0);
[Link](200 + size, 0, 200 + size, size / 2);
[Link](200 + size, size, 200 + size / 2, size);
[Link](200, size, 200, size / 2);
[Link](200, 0, 200 + size / 2, 0);
[Link](roundObject);

ActionScript 3.0
Graphics drawCircle() drawEllipse()
drawRect() drawRoundRect() drawRoundRectComplex()
lineTo() curveTo()
100
drawRect() Alpha 50% (0.5)
var squareSize:uint = 100;
var square:Shape = new Shape();
[Link](0xFF0000, 0.5);

392

API

[Link](0, 0, squareSize, squareSize);


[Link](0x00FF00, 0.5);
[Link](200, 0, squareSize, squareSize);
[Link](0x0000FF, 0.5);
[Link](400, 0, squareSize, squareSize);
[Link]();
[Link](square);

Sprite MovieClip graphics


graphics
Sprite MovieClip Sprite graphics
TextField
var mySprite:Sprite = new Sprite();
[Link](0xFFCC00);
[Link](30, 30, 30);
var label:TextField = new TextField();
[Link] = 200;
[Link] = "They call me mellow yellow...";
label.x = 20;
label.y = 20;
[Link](label);
[Link](mySprite);

TextField graphics

graphics
lineGradientStyle() beginGradientFill()

Alpha

[Link]
[Link]

Alpha

0-255
0 255

Alpha

393


Matrix Matrix
Matrix createGradientBox()

Matrix
[Link] beginGradientFill() lineGradientStyle()

Matrix createGradientBox()
createGradientBox()
createGradientBox()

[Link]

ratios [0, 255]

[Link]

InterpolationMethod.LINEAR_RGB

createGradientBox() rotation

width = 100;
height = 100;
rotation = 0;
tx = 0;
ty = 0;

394

API

width = 100;
height = 100;
rotation = [Link]/4; // 45
tx = 0;
ty = 0;

width = 100;
height = 100;
rotation = [Link]/2; // 90
tx = 0;
ty = 0;

createGradientBox()
rotation tx ty
width = 50;
height = 100;
rotation = 0;
tx = 0;
ty = 0;

width = 50;
height = 100;
rotation = 0
tx = 50;
ty = 0;

395

width = 100;
height = 50;
rotation = [Link]/2; // 90
tx = 0;
ty = 0;

width = 100;
height = 50;
rotation = [Link]/2; // 90
tx = 0;
ty = 50;

createGradientBox() widthheighttx ty

width = 50;
height = 100;
rotation = 0;
tx = 25;
ty = 0;

import [Link];
import [Link];
import [Link];
var
var
var
var
var
var
var

type:String = [Link];
colors:Array = [0x00FF00, 0x000088];
alphas:Array = [1, 1];
ratios:Array = [0, 255];
spreadMethod:String = [Link];
interp:String = InterpolationMethod.LINEAR_RGB;
focalPtRatio:Number = 0;

var matrix:Matrix = new Matrix();


var boxWidth:Number = 50;
var boxHeight:Number = 100;
var boxRotation:Number = [Link]/2; // 90
var tx:Number = 25;
var ty:Number = 0;
[Link](boxWidth, boxHeight, boxRotation, tx, ty);

396

API

var square:Shape = new Shape;


[Link](type,
colors,
alphas,
ratios,
matrix,
spreadMethod,
interp,
focalPtRatio);
[Link](0, 0, 100, 100);
addChild(square);

Graphics
Graphics
Graphics drawRect()

var myShape:Shape = new Shape();


var gradientBoxMatrix:Matrix = new Matrix();
[Link](100, 40, 0, 0, 0);
[Link]([Link], [0xFF0000, 0x00FF00,
0x0000FF], [1, 1, 1], [0, 128, 255], gradientBoxMatrix);
[Link](0, 0, 50, 40);
[Link](0, 50, 100, 40);
[Link](0, 100, 150, 40);
[Link]();
[Link](myShape);


drawRect() 50100 150beginGradientFill()
100
50

lineGradientStyle() beginGradientFill()

lineStyle()

var myShape:Shape = new Shape();


var gradientBoxMatrix:Matrix = new Matrix();
[Link](200, 40, 0, 0, 0);
[Link](5, 0);
[Link]([Link], [0xFF0000, 0x00FF00,
0x0000FF], [1, 1, 1], [0, 128, 255], gradientBoxMatrix);
[Link](0, 0, 200, 40);
[Link](myShape);

Matrix 379 Matrix

397

Math
Graphics
Math Math
[Link] 3.14159265...
[Link]() [Link]() [Link]()

Math Math

var degrees = 121;


var radians = degrees * [Link] / 180;
trace(radians) // 2.111848394913139

[Link]() [Link]()

var
var
var
var
var
var

sinWavePosition = 100;
cosWavePosition = 200;
sinWaveColor:uint = 0xFF0000;
cosWaveColor:uint = 0x00FF00;
waveMultiplier:Number = 10;
waveStretcher:Number = 5;

var i:uint;
for(i = 1; i < [Link]; i++)
{
var sinPosY:Number = [Link](i / waveStretcher) * waveMultiplier;
var cosPosY:Number = [Link](i / waveStretcher) * waveMultiplier;
[Link](sinWaveColor);
[Link](i, sinWavePosition + sinPosY, 2, 2);
[Link](cosWaveColor);
[Link](i, cosWavePosition + cosPosY, 2, 2);
}

398

API

API
API

Event.ENTER_FRAME
graphics
[Link] = 31;
var currentDegrees:Number = 0;
var radius:Number = 40;
var satelliteRadius:Number = 6;
var container:Sprite = new Sprite();
container.x = [Link] / 2;
container.y = [Link] / 2;
addChild(container);
var satellite:Shape = new Shape();
[Link](satellite);
addEventListener(Event.ENTER_FRAME, doEveryFrame);
function doEveryFrame(event:Event):void
{
currentDegrees += 4;
var radians:Number = getRadians(currentDegrees);
var posX:Number = [Link](radians) * radius;
var posY:Number = [Link](radians) * radius;
[Link]();
[Link](0);
[Link](posX, posY, satelliteRadius);
}
function getRadians(degrees:Number):Number
{
return degrees * [Link] / 180;
}

currentDegreesradius
satelliteRadius radius / totalSatellites
API

API

399

Algorithmic Visual Generator


Algorithmic Visual Generator

API

Event.ENTER_FRAME

satellites

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/AlgorithmicVisualGenerator

[Link]

Flash (FLA)

com/example/programmingas3/algorithmic/
[Link]

com/example/programmingas3/algorithmic/
[Link]

com/example/programmingas3/algorithmic/
[Link]

SWF SWF
doEveryFrame()

400

API


build() clear()
satellites
build()

position
color
satellites doEveryFrame()

doEveryFrame()

SWF

position radius orbitRadius


Satellite draw()

i visibleSatellites

doEveryFrame() visibleSatellites

ControlPanel

changeSetting()

doEveryFrame()

Algorithmic Visual Generator

401


API

doEveryFrame()

doEveryFrame()

Math

API Flash

API ActionScript

402

API

15

15

Adobe Photoshop Adobe


Fireworks ActionScript 3.0 [Link]

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Filter Workbench . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .424

ActionScript 3.0
BitmapData

ActionScript

BitmapData

403

SWF
API

1.

Flash

2.
3.
4. >

SWF

404

filters
BitmapData applyFilter()

DropShadowFilter
import [Link];
var myFilter:DropShadowFilter = new DropShadowFilter();

DropShadowFilter()

BitmapData

filters filters
Array
Array Array
filters
import [Link];
import [Link];
import [Link];
// bitmapData
var myBitmapData:BitmapData = new BitmapData(100,100,false,0xFFFF3300);
var myDisplayObject:Bitmap = new Bitmap(myBitmapData);
addChild(myDisplayObject);
// DropShadowFilter
var dropShadow:DropShadowFilter = new DropShadowFilter();
// Array()
//
var filtersArray:Array = new Array(dropShadow);

405

//
[Link] = filtersArray;

Array filters
Array
Array
import [Link];
import [Link];
//
var bevel:BevelFilter = new BevelFilter();
var glow:GlowFilter = new GlowFilter();
var filtersArray:Array = new Array(bevel, glow);
//
[Link] = filtersArray;

new Array()
Array ([])
var filters:Array = new Array(dropShadow, blur);

var filters:Array = [dropShadow, blur];

myDisplayObject

[Link] = [new BlurFilter()];

Array Array BlurFilter


Array Array myDisplayObject
filters

filters

null

[Link] = null;

filters 407

406

BitmapData
BitmapData

BitmapData applyFilter()

[Link](sourceBitmapData);
applyFilter()

BitmapData

BitmapData

applyFilter()

Adobe Flash Player

cacheAsBitmap
false Flash Player cacheAsBitmap
trueFlash Player cacheAsBitmap

filters

filters
myDisplayObject
addFilters()
myDisplayObject
import [Link];
import [Link].*;
[Link] = [new GlowFilter()];
function addFilters(event:MouseEvent):void

407

{
//
var filtersCopy:Array = [Link];
//
[Link](new BlurFilter());
[Link](new DropShadowFilter());
// filters
[Link] = filtersCopy;
}
[Link]([Link], addFilters);

DisplayObject

scaleX
scaleY 100%

BitmapData

BitmapData cacheAsBitmap true

cacheAsBitmap

408


ActionScript 3.0 9 BitmapData

BevelFilter

BlurFilter

DropShadowFilter

GlowFilter

GradientBevelFilter

GradientGlowFilter

ColorMatrixFilter

ConvolutionFilter

DisplacementMapFilter

ActionScript Adobe Flash CS3 Professional


ActionScript Flash

ActionScript

ActionScript 3.0
[Link]

BevelFilter

BevelFilter

409


import
import
import
import
import

[Link].*;
[Link];
[Link];
[Link];
[Link];

//
var imageLoader:Loader = new Loader();
var url:String = "[Link]
var urlReq:URLRequest = new URLRequest(url);
[Link](urlReq);
addChild(imageLoader);
//
var bevel:BevelFilter = new BevelFilter();
[Link] = 5;
[Link] = 45;
[Link] = 0xFFFF00;
[Link] = 0.8;
[Link] = 0x666666;
[Link] = 0.8;
[Link] = 5;
[Link] = 5;
[Link] = 5;
[Link] = [Link];
[Link] = [Link];
[Link] = false;
//
[Link] = [bevel];

BlurFilter

quality quality

Graphics drawCircle()
import [Link];
import [Link];
import [Link];
//
var redDotCutout:Sprite = new Sprite();
[Link]();

410

[Link](0xFF0000);
[Link](145, 90, 25);
[Link]();
//
addChild(redDotCutout);
//
var blur:BlurFilter = new BlurFilter();
[Link] = 10;
[Link] = 10;
[Link] = [Link];
[Link] = [blur];

Alpha

sprite
import [Link];
import [Link];
//
var boxShadow:Sprite = new Sprite();
[Link](1);
[Link](0xFF3300);
[Link](0, 0, 100, 100);
[Link]();
addChild(boxShadow);
//
var shadow:DropShadowFilter = new DropShadowFilter();
[Link] = 10;
[Link] = 25;
//
// Alpha
//
[Link] = [shadow];

411


GlowFilter

GlowFilter
Sprite
import [Link];
import [Link];
import [Link];
//
var crossGraphic:Sprite = new Sprite();
[Link]();
[Link](0xCCCC00);
[Link](60, 90, 100, 20);
[Link](100, 50, 20, 100);
[Link]();
addChild(crossGraphic);
//
var glow:GlowFilter = new GlowFilter();
[Link] = 0x009922;
[Link] = 1;
[Link] = 25;
[Link] = 25;
[Link] = [Link];
[Link] = [glow];

GradientBevelFilter BitmapData

Shape drawRect()
import [Link];
import [Link];
import [Link];
//
var box:Shape = new Shape();
[Link]();
[Link](0xFEFE78);
[Link](100, 50, 90, 200);
[Link]();

412

//
var gradientBevel:GradientBevelFilter = new GradientBevelFilter();
[Link] = 8;
[Link] = 225; // 45
[Link] = [0xFFFFCC, 0xFEFE78, 0x8F8E01];
[Link] = [1, 0, 1];
[Link] = [0, 128, 255];
[Link] = 8;
[Link] = 8;
[Link] = [Link];
//
//
[Link] = [gradientBevel];
//
addChild(box);

GradientGlowFilter BitmapData

import
import
import
import

[Link];
[Link];
[Link];
[Link];

// Shape
var shape:Shape = new Shape();
//
[Link](0xFF0000, 100);
[Link](0, 0);
[Link](100, 0);
[Link](100, 100);
[Link](0, 100);
[Link](0, 0);
[Link]();
//

413

addChild(shape);
shape.x = 100;
shape.y = 100;
//
var gradientGlow:GradientGlowFilter = new GradientGlowFilter();
[Link] = 0;
[Link] = 45;
[Link] = [0x000000, 0xFF0000];
[Link] = [0, 1];
[Link] = [0, 255];
[Link] = 10;
[Link] = 10;
[Link] = 2;
[Link] = [Link];
[Link] = [Link];
//
function onClick(event:MouseEvent):void
{
[Link]++;
[Link] = [gradientGlow];
}
function onMouseMove(event:MouseEvent):void
{
[Link] = ([Link] / [Link]) * 255;
[Link] = ([Link] / [Link]) * 255;
[Link] = [gradientGlow];
}
[Link]([Link], onClick);
[Link](MouseEvent.MOUSE_MOVE, onMouseMove);

import
import
import
import
import
import
import
import

Timer

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

var count:Number = 1;
var distance:Number = 8;

414

var
var
var
var
var
var
var
var
var
var

angleInDegrees:Number = 225; // 45
colors:Array = [0xFFFFCC, 0xFEFE78, 0x8F8E01];
alphas:Array = [1, 0, 1];
ratios:Array = [0, 128, 255];
blurX:Number = 8;
blurY:Number = 8;
strength:Number = 1;
quality:Number = [Link];
type:String = [Link];
knockout:Boolean = false;

//
var box:Shape = new Shape();
[Link]();
[Link](0xFEFE78);
[Link](100, 50, 90, 200);
[Link]();
// 3
var stopLight:Shape = new Shape();
[Link]();
[Link](0xFF0000);
[Link](145,90,25);
[Link]();
var cautionLight:Shape = new Shape();
[Link]();
[Link](0xFF9900);
[Link](145,150,25);
[Link]();
var goLight:Shape = new Shape();
[Link]();
[Link](0x00CC00);
[Link](145,210,25);
[Link]();
//
addChild(box);
addChild(stopLight);
addChild(cautionLight);
addChild(goLight);
//
var gradientBevel:GradientBevelFilter = new GradientBevelFilter(distance,
angleInDegrees, colors, alphas, ratios, blurX, blurY, strength, quality,
type, knockout);
[Link] = [gradientBevel];
//

415

//
var innerShadow:DropShadowFilter = new DropShadowFilter(5, 45, 0, 0.5, 3, 3,
1, 1, true, false);
var redGlow:GlowFilter = new GlowFilter(0xFF0000, 1, 30, 30, 1, 1, false,
false);
var yellowGlow:GlowFilter = new GlowFilter(0xFF9900, 1, 30, 30, 1, 1, false,
false);
var greenGlow:GlowFilter = new GlowFilter(0x00CC00, 1, 30, 30, 1, 1, false,
false);
// /
[Link] = [innerShadow];
[Link] = [innerShadow];
[Link] = [greenGlow];
//
function trafficControl(event:TimerEvent):void
{
if (count == 4)
{
count = 1;
}
switch (count)
{
case 1:
[Link] = [innerShadow];
[Link] = [yellowGlow];
[Link] = [innerShadow];
break;
case 2:
[Link] = [redGlow];
[Link] = [innerShadow];
[Link] = [innerShadow];
break;
case 3:
[Link] = [innerShadow];
[Link] = [innerShadow];
[Link] = [greenGlow];
break;
}
count++;
}
// 3
var timer:Timer = new Timer(3000, 9);
[Link]([Link], trafficControl);
[Link]();

416


ColorMatrixFilter Alpha
Alpha

Alpha

matrix 20
ActionScript 3.0
ColorMatrixFilter matrix
Adobe Using
Matrices for Transformations, Color Adjustments, and Convolution Effects in Flash
Flash

ConvolutionFilter BitmapData

x 3

N N N
N P N
N N N

Flash Player P
N

0 0 0
0 1 0
0 0 0

417

1
0

0 0 0
0 0 1
0 0 0

ActionScript Array

//
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("[Link]
images/[Link]");
[Link](url);
[Link](loader);
function applyFilter(event:MouseEvent):void
{
//
var matrix:Array = [ 0, 0, 0,
0, 0, 1,
0, 0, 0 ];
var convolution:ConvolutionFilter = new ConvolutionFilter();
[Link] = 3;
[Link] = 3;
[Link] = matrix;
[Link] = 1;
[Link] = [convolution];
}
[Link]([Link], applyFilter);

1 0
8 1
8
divisor
divisor 1
divisor 8 1
8

418


3 x 3

5
0 1 0
1 1 1
0 1 0

1)
0, -1, 0
-1, 5, -1
0, -1, 0

1
0, -1, 0
-1, 4, -1
0, -1, 0

1
-2, -1, 0
-1, 1, 1
0, 1, 2

1 1
0 divisor 0

DisplacementMapFilter BitmapData
BitmapData

X x
Y y
X x
Y y

419

Flash Player
DisplacementMapFilterMode
IGNORE WRAP

CLAMP COLOR

import
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

//
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("[Link]
images/[Link]");
[Link](url);
[Link](loader);
var mapImage:BitmapData;
var displacementMap:DisplacementMapFilter;
// This function is called when the image finishes loading.
function setupStage(event:Event):void
{
//
loader.x = ([Link] - [Link]) / 2;
loader.y = ([Link] - [Link]) / 2;
//
mapImage = new BitmapData([Link], [Link], false, 0xFF0000);
//
displacementMap = new DisplacementMapFilter();
[Link] = mapImage;
[Link] = new Point(0, 0);
[Link] = [Link];
[Link] = 250;
[Link] = [displacementMap];
}
[Link]([Link], setupStage);

420

BitmapData

0, 0

X [Link]
x

X 250
1
0.5 250 125
250
Flash Player

1.

Flash Player Flash

Player

2.

Flash Player x
Flash Player
0xFF 255

Flash Player 127 0 255


x y
x y
Flash Player 127
4. Flash Player
100% x y
100% 250
125
y y
3.

WRAP

[Link] = [displacementMap]

[Link] = [Link];

421


import
import
import
import
import
import
import
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

//
//
var radius:uint = 50;
var type:String = [Link];
var redColors:Array = [ 0xFF0000, 0x000000 ];
var blueColors:Array = [ 0x0000FF, 0x000000 ];
var alphas:Array = [ 1, 1 ];
var ratios:Array = [ 0, 255 ];
var xMatrix:Matrix = new Matrix();
[Link](radius * 2, radius * 2);
var yMatrix:Matrix = new Matrix();
[Link](radius * 2, radius * 2, [Link] / 2);
var xCircle:Shape = new Shape();
[Link](0, 0, 0);
[Link](type, redColors, alphas, ratios,
xMatrix);
[Link](radius, radius, radius);
var yCircle:Shape = new Shape();
[Link](0, 0, 0);
[Link](type, blueColors, alphas, ratios,
yMatrix);
[Link](radius, radius, radius);
//
[Link](xCircle);
xCircle.y = [Link] - [Link];
[Link](yCircle);
yCircle.y = [Link] - [Link];
yCircle.x = 200;

422

//
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("[Link]
images/[Link]");
[Link](url);
[Link](loader);
//
var map:BitmapData = new BitmapData([Link], [Link], false,
0x7F7F7F);
[Link](xCircle);
var yMap:BitmapData = new BitmapData([Link], [Link], false,
0x7F7F7F);
[Link](yCircle);
[Link](yMap, [Link], new Point(0, 0), [Link],
[Link]);
[Link]();
//
var mapBitmap:Bitmap = new Bitmap(map);
[Link](mapBitmap);
mapBitmap.x = 400;
mapBitmap.y = [Link] - [Link];
//
function magnify():void
{
//
var filterX:Number = ([Link]) - ([Link] / 2);
var filterY:Number = ([Link]) - ([Link] / 2);
var pt:Point = new Point(filterX, filterY);
var xyFilter:DisplacementMapFilter = new DisplacementMapFilter();
[Link] = map;
[Link] = pt;
// x
[Link] = [Link];
// y
[Link] = [Link];
[Link] = 35;
[Link] = 35;
[Link] = [Link];
[Link] = [xyFilter];
}
//
//
function moveMagnifier(event:MouseEvent):void
{
if ([Link]([Link], [Link]))
{

423

magnify();
}
}
[Link](MouseEvent.MOUSE_MOVE, moveMagnifier);

x
= [Link]) y
= [Link])

([Link]
([Link]

0x7F7F7F

Filter Workbench
Filter Workbench
ActionScript
[Link]/go/learn_fl_filters_cn

424

16

16

MovieClip Adobe Flash CS3 Professional

ActionScript

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .425
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
ActionScript MovieClip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
SWF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .433
RuntimeAssetsExplorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .434

Flash ActionScript
Flash Flash
Flash MovieClip
MovieClip

ActionScript MovieClip
Flash
Sprite
ActionScript MovieClip ActionScript 3.0

Shape Sprite MovieClip


338 DisplayObject

425

ActionScript

ActionScript

ActionScript

SWF

ActionScript

Flash Player

AVM1 SWF ActionScript 1.0 ActionScript 2.0 SWF


Flash Player 8
AVM2 SWF ActionScript 3.0 for Adobe Flash Player 9 SWF
SWF SWF SWF SWF
SWF

MovieClip
Flash


ActionScript
Flash Player

1.

Flash

2.
3.

426

4. >

5.

myMovieClip
myMovieClip
6. >

53

MovieClip
SWF Flash MovieClip
ActionScript
SWF Flash MovieClip

childClip parentClip

[Link]()

ActionScript 2.0 MovieClip


_width _height
width height _xscale _yscale scaleX scaleY
MovieClip ActionScript 3.0

Flash
MovieClip MovieClip ActionScript

Flash

MovieClip SWF
ActionScript [Link]

427


play() stop()

bicycle

[Link]();

startButton

//
//
function playAnimation(event:MouseEvent):void
{
[Link]();
}
//
[Link]([Link], playAnimation);

play() stop() nextFrame()


prevFrame()

play() enterFrame nextFrame()


enterFrame bicycle
bicycle
// enterFrame
//
function everyFrame(event:Event):void
{
if ([Link] == 1)
{
[Link]([Link]);
}
else
{
[Link]();
}
}
[Link](Event.ENTER_FRAME, everyFrame);

428


1 prevFrame() nextFrame()
1 prevFrame()
if

gotoAndPlay() gotoAndStop()


ActionScript
ActionScript

ActionScript 3.0 FrameLabel


name
frame
FrameLabel MovieClip
FrameLabel currentLabels
FrameLabel currentLabel
FrameLabel

currentLabel
if ([Link] == "walking"
{
//
}

429


Flash SWF
gotoAndPlay() gotoAndStop()
FLA
Flash

MovieClip scenes SWF Scene


currentScene Scene
Scene labels
FrameLabel name numFrames

ActionScript MovieClip
Flash

ActionScript

ActionScript 3.0 API MovieClip


MovieClip

ActionScript 3.0
addChild() addChildAt()

329

ActionScript
Flash
ActionScript ActionScript SWF

ActionScript ActionScript

430

ActionScript
1.
2.
3.

ActionScript


Tree House
TreeHouse
ActionScript

[Link]
Sprite MovieClip

4.

Flash ActionScript

SWF

MovieClip
Flash
package
{
import [Link];
public class ExampleMovieClip extends MovieClip
{
public function ExampleMovieClip()
{
}
}
}

ActionScript
50 50 Circle
ActionScript [Link] MovieClip
getArea() getCircumference()
package
{
import [Link];
public class Circle extends MovieClip
{

ActionScript MovieClip

431

public function Circle()


{
}
public function getArea():Number
{
// Pi
return [Link] * [Link]((width / 2), 2);
}
public function getCircumference():Number
{
// Pi
return [Link] * width;
}
}
}

Flash

var c:Circle = new Circle();


addChild(c);
trace([Link]);
trace([Link]);
trace([Link]());
trace([Link]());

ActionScript
Circle

ActionScript

Circle Flash
Circle 1
import [Link];
var totalCircles:uint = 10;
var i:uint;
for (i = 0; i < totalCircles; i++)
{
// Circle
var c:Circle = new Circle();
// Circle
// x
c.x = ([Link] / totalCircles) * i;
// Circle
c.y = [Link] / 2;
// Circle

432

[Link] = getRandomColor();
// Circle
addChild(c);
}
function getRandomColor():ColorTransform
{
//
var red:Number = ([Link]() * 512) - 255;
var green:Number = ([Link]() * 512) - 255;
var blue:Number = ([Link]() * 512) - 255;
// ColorTransform
return new ColorTransform(1, 1, 1, 1, red, green, blue, 0);
}

transform Circle MovieClip

SWF
ActionScript 3.0 SWF
ActionScript 4
1.

Loader SWF

URL URLRequest

2.

Loader

3.
4.

Loader load() URLRequest


Flash addChild() Loader

var request:URLRequest = new URLRequest([Link]


[Link]);
var loader:Loader = new Loader()
[Link](request);
addChild(loader);

SWF

433

URL SWF URL


JPEGGIF PNG SWF ActionScript
SWF
ActionScript SWF SWF
SWF SWF SWF
SWF SWF

603 ApplicationDomain 665 SWF


SWF [Link] SWF
ActionScript 3.0 sprite

SWF
ActionScript SWF
AVM2 (ActionScript Virtual Machine 2) ActionScript 3.0 SWF
ActionScript 1.0 2.0 SWF AVM1 (ActionScript Virtual
Machine 1)
AVM1 SWF [Link] AVM1Movie
AVM1Movie MovieClip
AVM2 SWF AVM1Movie

AVM2 SWF AVM1 SWF


ActionScript 3.0 AVM1Movie

RuntimeAssetsExplorer

ActionScript
ActionScript SWF SWF
SWF Flash SWF

SWF SWF

434

RuntimeAssetsExplorer RuntimeAsset SWF


SWF

[Link]() SWF

ActionScript

ActionScript

MovieClip

SWF 660

[Link]/go/learn_programmingAS3samples_flash_cn RuntimeAssetsExplorer
Samples/RuntimeAssetsExplorer

[Link]

Flex (MXML) Flash (FLA)

[Link]
[Link]

RuntimeAsset

[Link]

GeometricAssets FLA
FLA ActionScript

com/example/programmingas3/
runtimeassetsexplorer/[Link]

SWF

com/example/programmingas3/
runtimeassetsexplorer/[Link]

com/example/programmingas3/
runtimeassetsexplorer/[Link]

SWF

SWF
131

RuntimeLibrary
getAssets()
package [Link]
{
public interface RuntimeLibrary
{

RuntimeAssetsExplorer

435

function getAssets():Array;
}
}

SWF
RuntimeLibrary
SWF SWF

SWF

SWF

SWF

RuntimeLibrary
RuntimeLibrary GeometricAssets FLA
RuntimeLibrary
getAssets()
package
{
import [Link];
import [Link];
public class GeometricAssets extends Sprite implements RuntimeLibrary
{
public function GeometricAssets() {
}
public function getAssets():Array {
return [
"[Link]",
"[Link]"
];
}
}
}

AnimationAssets
FLA getAssets()

436

MovieClip
MovieClip
AnimatingStar AnimatingBox
package [Link]
{
import [Link];
public class AnimatingStar extends MovieClip
{
public function AnimatingStar() {
}
}
}

MovieClip FLA
GeometricAssets
360 animatingBox
animatingStar ActionScript getAssets()
[Link]
MovieClip
FLA SWF
AVM2 SWF AnimatingBox AnimatingStar
SWF

SWF

ASSETS_PATH FileReference
SWF
Flash

Player runtimeAssetsLoadComplete()

private function runtimeAssetsLoadComplete(event:Event):void


{
var rl:* = [Link];
var assetList:Array = [Link]();
populateDropdown(assetList);
[Link] = 60;
}

RuntimeAssetsExplorer

437

rl SWF SWF
getAssets() populateDropDown()
ComboBox
addAsset()
private function addAsset():void
{
var className:String = [Link];
var AssetClass:Class = getDefinitionByName(className) as Class;
var mc:MovieClip = new AssetClass();
...
}

ComboBox ([Link])
getDefinitionByName() [Link]

438

17

17

ActionScript 3.0
UI
Adobe Flash CS3
Professional ActionScript 3.0

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .442
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .446
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .448
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .453
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .455
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .456

439

Adobe Flash Player TextField TextField


Adobe Flex Flash TextArea
TextInput Flash
Flash
SWF
HTML
[Link] TextFormat
StyleSheet [Link] ActionScript

TextFormat
HTML StyleSheet
TextFormat StyleSheet
TextFormat

449
HTML 443

HTML

450
[Link]

HTML

CSS

440

[Link]

ActionScript

(Cascading style sheet) XML

HTML

(Device font)

(Dynamic

(Embedded font) SWF

HTML ActionScript HTML

(Input text field)

(Static text

(Text line metri)


text field) ActionScript

ActionScript

field) Flash SWF


ActionScript TextField
Flash ActionScript
Flash Player

1.

TextField

Flash

2.
3.
4.
5.

myTextField
myTextField

441

6. >

SWF
TextField

1.

Flash

2.

ActionScript Flash
TextFieldTest
[Link] ActionScript

3.

ActionScript

4.
5.
6.

Flash
ActionScript
>

53

Adobe Flex Builder Flash

XML Web
442

[Link]
447

Flash ActionScript 3.0


ActionScript StaticText TextSnapshot
455

442


[Link]

[Link] = Hello World;

text
package
{
import [Link];
import [Link].*;
public class TextWithImage extends Sprite
{
private var myTextBox:TextField = new TextField();
private var myText:String = "Hello World";
public function TextWithImage()
{
addChild(myTextBox);
[Link] = myText;
}
}
}

text

[Link] [Link]

FlashVars

SWF HTML
[Link] 576

HTML
[Link] htmlText
HTML htmlText
text Flash Player HTML
var myText:String = "<p>This is <b>some</b> content to <i>render</i> as
<u>HTML</u> text.</p>";
[Link] = myText;

Flash Player htmlText HTML


ActionScript 3.0 [Link]
HTML

443

htmlText textformat
449

HTML img

myTextBox
JPG SWF
package
{
import [Link];
import [Link].*;
public class TextWithImage extends Sprite
{
private var myTextBox:TextField;
private var myText:String = "<p>This is <b>some</b> content to <i>test</
i> and <i>see</i></p><p><img src='[Link]' width='20' height='20'></
p><p>what can be rendered.</p><p>You should see an eye image and some
<u>HTML</u> text.</p>";
public function TextWithImage()
{
[Link] = 200;
[Link] = 200;
[Link] = true;
[Link] = true;
[Link] = true;
addChild(myTextBox);
[Link] = myText;
}
}
}
img

JPEG GIF PNG SWF

[Link]

[Link] [Link] maxScrollV
maxScrollH

444

package
{
import [Link];
import [Link].*;
import [Link];
public class TextScrollExample extends Sprite
{
private var myTextBox:TextField = new TextField();
private var myText:String = "Hello world and welcome to the show. It's
really nice to meet you. Take your coat off and stay a while. OK, show is
over. Hope you had fun. You can go home now. Don't forget to tip your
waiter. There are mints in the bowl by the door. Thank you. Please come
again.";
public function TextScrollExample()
{
[Link] = myText;
[Link] = 200;
[Link] = 50;
[Link] = true;
[Link] = true;
[Link] = true;
[Link] = true;
var format:TextFormat = new TextFormat();
[Link] = "Verdana";
[Link] = 0xFF0000;
[Link] = 10;
[Link] = format;
addChild(myTextBox);
[Link](MouseEvent.MOUSE_DOWN, mouseDownScroll);
}
public function mouseDownScroll(event:MouseEvent):void
{
[Link]++;
}
}
}

445


TextField

Flash

[Link] true setSelection()

var myTextField:TextField = new TextField();


[Link] = "No matter where you click on this text field the TEXT IN
ALL CAPS is selected.";
[Link] = [Link];
addChild(myTextField);
addEventListener([Link], selectText);
function selectText(event:MouseEvent):void
{
[Link](49, 65);
}

TextField selectionBeginIndex selectionEndIndex



caretIndex

var myTextField:TextField = new TextField();


[Link] = "Please select the TEXT IN ALL CAPS to see the index
values for the first and last letters.";
[Link] = [Link];
addChild(myTextField);
addEventListener(MouseEvent.MOUSE_UP, selectText);
function selectText(event:MouseEvent):void
{

446

trace("First letter index position: " + [Link]);


trace("Last letter index position: " + [Link]);
}

TextFormat
TextFormat 452

type dynamic TextFieldType type


input

myTextBox
textInput textInputCapture
Flash Player myOutputBox

package
{
import
import
import
import

[Link];
[Link];
[Link].*;
[Link].*;

public class CaptureUserInput extends Sprite


{
private var myTextBox:TextField = new TextField();
private var myOutputBox:TextField = new TextField();
private var myText:String = "Type your text here.";
public function CaptureUserInput()
{
captureText();
}
public function captureText():void
{
[Link] = [Link];
[Link] = true;
addChild(myTextBox);
[Link] = myText;
[Link](TextEvent.TEXT_INPUT, textInputCapture);
}

447

public function textInputCapture(event:TextEvent):void


{
var str:String = [Link];
createOutputBox(str);
}
public function createOutputBox(str:String):void
{
[Link] = true;
myOutputBox.x = 200;
addChild(myOutputBox);
[Link] = str;
}
}
}


[Link] displayAsPassword restrict
displayAsPassword
displayAsPassword true

displayAsPassword

[Link] = [Link];
[Link] = true;
[Link] = true;
addChild(myTextBox);
restrict


[Link] = A-Z;

ActionScript 3.0
ActionScript 3.0
[Link]

448


TextField
[Link] [Link]
htmlText HTML b i
u TextFormat StyleSheet
htmlText TextFormat StyleSheet
TextFormat StyleSheet

TextFormat

TextField
TextFormat

TextField

TextFormat TextField

var tf:TextField = new TextField();


[Link] = "Hello Hello";
var format1:TextFormat = new TextFormat();
[Link] = 0xFF0000;
var format2:TextFormat = new TextFormat();
[Link] = "Courier";
[Link](format1);
var startRange:uint = 6;
[Link](format2, startRange);
addChild(tf);
[Link]() TextField
[Link]()
TextField defaultTextFormat

449


HTML text
HTML htmlText
CSS CSS
CSS

[Link] CSS StyleSheet CSS


StyleSheet ActionScript 3.0
[Link]
CSS StyleSheet HTML

var style:StyleSheet = new StyleSheet();


var styleObj:Object = new Object();
[Link] = "bold";
[Link] = "#FF0000";
[Link](".darkRed", styleObj);
var tf:TextField = new TextField();
[Link] = style;
[Link] = "<span class = 'darkRed'>Red</span> apple";
addChild(tf);

StyleSheet
[Link]() .darkred
StyleSheet TextField styleSheet

CSS htmlText

TextField

ActionScript API

[Link]()

[Link]()

[Link]

[Link]()

[Link]
null [Link] [Link]
htmlText
null

450

CSS
CSS CSS
CSS
ActionScript 3.0 CSS
SWF

CSS StyleSheet
CSS TextField

[Link]()

CSS [Link]
p {
font-family: Times New Roman, Times, _serif;
font-size: 14;
}
h1 {
font-family: Arial, Helvetica, _sans;
font-size: 20;
font-weight: bold;
}
.bluetext {
color: #0000CC;
}

[Link]
package
{
import
import
import
import
import
import
import

TextField ActionScript

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

public class CSSFormattingExample extends Sprite


{
var loader:URLLoader;
var field:TextField;
var exampleText:String = "<h1>This is a headline</h1>" +
"<p>This is a line of text. <span class='bluetext'>" +
his line of text is colored blue.</span></p>";
public function CSSFormattingExample():void
{
field = new TextField();
[Link] = 300;

451

[Link] = [Link];
[Link] = true;
addChild(field);
var req:URLRequest = new URLRequest("[Link]");
loader = new URLLoader();
[Link]([Link], onCSSFileLoaded);
[Link](req);
}
public function onCSSFileLoaded(event:Event):void
{
var sheet:StyleSheet = new StyleSheet();
[Link]([Link]);
[Link] = sheet;
[Link] = exampleText;
}
}
}

CSS onCSSFileLoaded() [Link]()


StyleSheet

[Link] setTextFormat()
setTextFormat()

[Link]()
myTextField
var myTextField:TextField = new TextField();
[Link] = "No matter where you click on this text field the TEXT IN
ALL CAPS changes format.";
[Link] = [Link];
addChild(myTextField);
addEventListener([Link], changeText);
var myformat:TextFormat = new TextFormat();
[Link] = 0xFF0000;
[Link] = 18;
[Link] = true;
function changeText(event:MouseEvent):void
{
[Link](myformat, 49, 65);
}

452


ActionScript 3.0 [Link]
alpha ActionScript 3.0
CSMSettings Font TextRenderer

TextField Flash Player


SWF

CSS

SWF
TextField

TextField embedFonts true

TextFormat fontFamily TextField


TextFormat fontFamily

CSS TextField font-family CSS


font-family

453

Flash
Flash TrueType Type 1
Postscript
Flash

TextField

Flash

Flash

Flash Player

[Link] CSMSettings Flash Player

453

[Link] [Link]
gridFitType
[Link]()

myFont
Flash Player
var format:TextFormat = new TextFormat();
[Link] = 0x336699;
[Link] = 48;
[Link] = "myFont";
var myText:TextField = new TextField();
[Link] = true;
[Link] = [Link];
[Link] = [Link];
[Link] = format;
[Link] = false;
[Link] = true;
[Link] = "Hello World";
addChild(myText);
[Link]([Link], clickHandler);
function clickHandler(event:Event):void

454

(CSM)

{
var myAntiAliasSettings = new CSMSettings(48, 0.8, -0.8);
var myAliasTable:Array = new Array(myAntiAliasSettings);
[Link]("myFont", [Link],
TextColorType.DARK_COLOR, myAliasTable);
}

Flash ActionScript

Flash
ActionScript 3.0 [Link]
[Link]

StaticText
Flash [Link]
SWF
ActionScript
Flash CS3
ActionScript 3.0

for (var i = 0; i < [Link]; i++) {


var displayitem:DisplayObject = [Link](i);
if (displayitem instanceof StaticText) {
trace("a static text field is item " + i + " on the display list");
var myFieldLabel:StaticText = StaticText(displayitem);
trace("and contains the text: " + [Link]);
}
}

ActionScript 3.0
myFieldLabel
myFieldLabel x y myField
myFieldLabel
var myField:TextField = new TextField();
addChild(myField);
myField.x = myFieldLabel.x;
myField.y = myFieldLabel.y + 20;
[Link] = [Link];
[Link] = "and " + [Link]

455

TextSnapshot
[Link]
[Link] textSnapshot
[Link] TextSnapshot

TextSnapshot
ActionScript 1

Example

var mySnap:TextSnapshot = [Link]();


var count:Number = [Link]();
[Link](0, 4, true);
[Link](1, 2, false);
var myText:String = [Link](false);
trace(myText);

TextSnapshot SWF

ActionScript

TextField

CSS

CSS

TextLineMetrics

TextFormat

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/NewsLayout

[Link]

Flex (MXML) Flash (FLA)

[Link]
[Link]

456

ActionScript

[Link]

TextFormat TextField

[Link]

FormattedTextField

[Link]

ActionScript

[Link]

CSS

[Link]

XML

CSS
XML
CSS

CSS h1 h2

p {
font-family: Georgia, Times New Roman, Times, _serif;
font-size: 12;
leading: 2;
text-align: justify;
}
h1 {
font-family: Verdana, Arial, Helvetica, _sans;
font-size: 20;
font-weight: bold;
color: #000099;
text-align: left;
}
h2 {
font-family: Verdana, Arial, Helvetica, _sans;
font-size: 16;
font-weight: normal;
text-align: left;
}

457

CSS 451 CSS


CSS onCSSFileLoaded()
public function onCSSFileLoaded(event:Event):void
{
[Link] = new StyleSheet();
[Link]([Link]);
h1Format = getTextStyle("h1", [Link]);
if (h1Format == null)
{
h1Format = getDefaultHeadFormat();
}
h2Format = getTextStyle("h2", [Link]);
if (h2Format == null)
{
h2Format = getDefaultHeadFormat();
[Link] = 16;
}
displayStory();
}
onCSSFileLoaded() StyleSheet CSS
MultiColumnTextField StyleSheet
HeadlineTextField TextFormat

CSS
TextFormat HeadlineTextField

onCSSFileLoaded() getTextStyle()
getTextStyle()

public function getTextStyle(styleName:String, ss:StyleSheet):TextFormat


{
var format:TextFormat = null;
var style:Object = [Link](styleName);
if (style != null)
{
var colorStr:String = [Link];
if (colorStr != null && [Link]("#") == 0)
{
[Link] = [Link](1);
}
format = new TextFormat([Link],
[Link],
[Link],
([Link] == "bold"),
([Link] == "italic"),
([Link] == "underline"),
[Link],
[Link],

458

[Link],
[Link],
[Link],
[Link],
[Link]);
if ([Link]("letterSpacing"))
{
[Link] = [Link];
}
}
return format;
}

CSS TextFormat getTextStyle()


CSS TextFormat

StoryLayout
displayText()
public function displayText():void
{
headlineTxt = new HeadlineTextField(h1Format);
[Link] = true;
[Link](headlineTxt);
[Link] = 600;
[Link] = 100;
[Link]([Link], 1, true);
subtitleTxt = new HeadlineTextField(h2Format);
[Link] = true;
subtitleTxt.y = headlineTxt.y + [Link];
[Link](subtitleTxt);
[Link] = 600;
[Link] = 100;
[Link]([Link], 1, false);
storyTxt = new MultiColumnTextField(2, 10, 600, 200);
storyTxt.y = subtitleTxt.y + [Link] + 4;
[Link](storyTxt);
[Link] = [Link];
[Link] = loremIpsum;
}

y y
HeadlineTextField MultiColumnTextField

459


HeadlineTextField

[Link]()
public function fitText(msg:String, maxLines:uint = 1, toUpper:Boolean =
false, targetWidth:Number = -1):uint
{
[Link] = toUpper ? [Link]() : msg;
if (targetWidth == -1)
{
targetWidth = [Link];
}
var pixelsPerChar:Number = targetWidth / [Link];
var pointSize:Number = [Link](MAX_POINT_SIZE, [Link](pixelsPerChar *
1.8 * maxLines));
if (pointSize < 6)
{
//
return pointSize;
}
[Link](pointSize);
if ([Link] > maxLines)
{
return shrinkText(--pointSize, maxLines);
}
else
{
return growText(pointSize, maxLines);
}
}
public function growText(pointSize:Number, maxLines:uint = 1):Number
{
if (pointSize >= MAX_POINT_SIZE)
{
return pointSize;
}
[Link](pointSize + 1);

460

if ([Link] > maxLines)


{
//
[Link](pointSize);
return pointSize;
}
else
{
return growText(pointSize + 1, maxLines);
}
}
public function shrinkText(pointSize:Number, maxLines:uint=1):Number
{
if (pointSize <= MIN_POINT_SIZE)
{
return pointSize;
}
[Link](pointSize);
if ([Link] > maxLines)
{
return shrinkText(pointSize - 1, maxLines);
}
else
{
return pointSize;
}
}
[Link]()

shrinkText() growText()

461


MultiColumnTextField TextField

MultiColumnTextField()

TextField

for (var i:int = 0; i < cols; i++)


{
var field:TextField = new TextField();
[Link] = [Link];
[Link] = true;
[Link] = [Link];
[Link](field);
[Link](field);
}

TextField addChild()
StoryLayout text styleSheet
layoutColumns() layoutColumns() getOptimalHeight()

public function getOptimalHeight(str:String):int
{
if ([Link] == 0 || str == "" || str == null)
{
return [Link];
}
else
{
var colWidth:int = [Link]( ([Link] (([Link] - 1) * gutter)) / [Link]);
var field:TextField = fieldArray[0] as TextField;
[Link] = colWidth;
[Link] = str;
var linesPerCol:int = [Link]([Link] / [Link]);
var metrics:TextLineMetrics = [Link](0);
var prefHeight:int = linesPerCol * [Link];
return prefHeight + 4;
}
}

462

getOptimalHeight() TextField
htmlText getOptimalHeight() TextField

[Link]() TextLineMetrics
[Link]
MultiColumnTextField
4 TextField 2
layoutColumns()
public function layoutColumns():void
{
if (this._text == "" || this._text == null)
{
return;
}
if ([Link])
{
[Link] = [Link](this._text);
}
var colWidth:int = [Link]( ([Link] ((numColumns - 1) * gutter)) / numColumns);
var field:TextField;
var remainder:String = this._text;
var fieldText:String = "";
for (var i:int = 0; i < [Link]; i++)
{
field = [Link][i] as TextField;
[Link] = colWidth;
[Link] = [Link];
field.x = i * (colWidth + gutter);
field.y = 0;
[Link] = "<p>" + remainder + "</p>";
remainder = "";
fieldText = "";
var linesRemaining:int = [Link];
var linesVisible:int = [Link] - [Link] + 1;
for (var j:int = 0; j < linesRemaining; j++)
{
if (j < linesVisible)
{
fieldText += [Link](j);

463

}
else
{
remainder +=
}

[Link](j);

}
[Link] = "<p>" + fieldText + "</p>";
}
}

getOptimalHeight() preferredHeight layoutColumns()


TextField preferredHeight
layoutColumns()

464

18

18

ActionScript 3.0 SWF

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .465
Bitmap BitmapData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .468
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .470
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476

RGB
0 255
255 102 0

465



16 48
48 16

Adobe Flash Player GIFJPG


PNG

GIF
(GIF) CompuServe 1987 256 8
Web
GIF GIF

JPEG
(JPEG) JPEG JPG
24
JPEG

PNG
(PNG) GIF
PNG 64 1600 PNG
PNG JPG PNG
PNG Alpha
256

466


GIF PNG Alpha

GIF 256
PNG 256

ActionScript 3.0 BitmapData PNG


[Link] 256

ActionScript

Alpha Alpha
Alpha

ARGB
Alpha

RGB

467

SWF

1.

Flash

2.
3.
4. >

SWF

Adobe
Flash CS3 Professional SWF
360

Bitmap BitmapData
ActionScript 3.0 Bitmap
BitmapData

Bitmap
DisplayObject Bitmap ActionScript 3.0
[Link] Flash Bitmap()
Bitmap GIF JPEG PNG
Bitmap BitmapData
Bitmap
Bitmap 319 12

Bitmap
Flash Bitmap pixelSnapping Bitmap
PixelSnapping ALWAYS
AUTO NEVER

[Link] = [Link];

468

BitmapData smoothing true

BitmapData
BitmapData [Link]
BitmapData

BitmapData
var myBitmap:BitmapData = new BitmapData(width:Number, height:Number,
transparent:Boolean, fillColor:uinit);
width height 2880 transparent
(true) (false) Alpha fillColor 32
true 50%
BitmapData
var myBitmap:BitmapData = new BitmapData(150, 150, true, 0x80FF3300);

BitmapData Bitmap
Bitmap BitmapData
Bitmap bitmapData Bitmap
addChild() addChildAt() Bitmap
329
BitmapData

Bitmap

var myBitmapDataObject:BitmapData = new BitmapData(150, 150, false, 0xFF0000);


var myImage:Bitmap = new Bitmap(myBitmapDataObject);
addChild(myImage);

Bitmap BitmapData

469


BitmapData

getPixel()
getPixel()

x, y RGB
Alpha getPixel32()
RGB getPixel() getPixel32() Alpha

setPixel()
setPixel32() x, y

setPixel() BitmapData
getPixel() 50, 50
import [Link];
import [Link];
var myBitmapData:BitmapData = new BitmapData(100, 100, false, 0x009900);
for (var i:uint = 0; i < 100; i++)
{
var red:uint = 0xFF0000;
[Link](50, i, red);
[Link](i, 50, red);
}
var myBitmapImage:Bitmap = new Bitmap(myBitmapData);
addChild(myBitmapImage);
var pixelValue:uint = [Link](50, 50);
trace([Link](16));

getPixels()

32
setPixels()
rect inputByteArray (inputByteArray) (rect)

470

inputByteArray
[Link]() inputByteArray

32 Alpha
(ARGB)
getPixels() setPixels() BitmapData

import
import
import
import

[Link];
[Link];
[Link];
[Link];

var bitmapDataObject1:BitmapData = new BitmapData(100, 100, false,


0x006666FF);
var bitmapDataObject2:BitmapData = new BitmapData(100, 100, false,
0x00FF0000);
var rect:Rectangle = new Rectangle(0, 0, 100, 100);
var bytes:ByteArray = [Link](rect);
[Link] = 0;
[Link](rect, bytes);
var bitmapImage1:Bitmap = new Bitmap(bitmapDataObject1);
addChild(bitmapImage1);
var bitmapImage2:Bitmap = new Bitmap(bitmapDataObject2);
addChild(bitmapImage2);
bitmapImage2.x = 110;

[Link]()
[Link]()

firstPoint

(Point) BitmapData

firstAlphaThreshold

(uint) Alpha

(Object)secondObject Rectangle
Point Bitmap BitmapData
secondBitmapDataPoint (Point) BitmapData
secondObject BitmapData
secondObject

null

471

secondAlphaThreshold (uint) BitmapData


Alpha 1 secondObject BitmapData
BitmapData

ActionScript

ActionScript Alpha

false true

import [Link];
import [Link];
import [Link];
var bmd1:BitmapData = new BitmapData(100, 100, false, 0x000000FF);
var bmd2:BitmapData = new BitmapData(20, 20, false, 0x00FF3300);
var bm1:Bitmap = new Bitmap(bmd1);
[Link](bm1);
// Create a red square.
var redSquare1:Bitmap = new Bitmap(bmd2);
[Link](redSquare1);
redSquare1.x = 0;
// Create a second red square.
var redSquare2:Bitmap = new Bitmap(bmd2);
[Link](redSquare2);
redSquare2.x = 150;
redSquare2.y = 150;
// Define the
var pt1:Point
// Define the
var pt2:Point
// Define the
var pt3:Point

point
= new
point
= new
point
= new

at the top-left corner of the bitmap.


Point(0, 0);
at the center of redSquare1.
Point(20, 20);
at the center of redSquare2.
Point(160, 160);

trace([Link](pt1, 0xFF, pt2)); // true


trace([Link](pt1, 0xFF, pt3)); // false

472


clone()copyPixels()
copyChannel() draw()
clone() BitmapData
BitmapData


import [Link];
import [Link];
var myParentSquareBitmap:BitmapData = new BitmapData(100, 100, false,
0x00ff3300);
var myClonedChild:BitmapData = [Link]();
var myParentSquareContainer:Bitmap = new Bitmap(myParentSquareBitmap);
[Link](myParentSquareContainer);
var myClonedChildContainer:Bitmap = new Bitmap(myClonedChild);
[Link](myClonedChildContainer);
myClonedChildContainer.x = 110;
copyPixels()

BitmapData

sourceRect
destPoint
copyChannel()

BitmapData Alpha
BitmapData
BitmapData
draw()

sprite

matrix colorTransform blendMode clipRect


Flash Player
draw() sprite

[Link](movieClip);

transform
BitmapData Bitmap transform

473


noise() perlinNoise()

noise()

randomSeed

(int)

[Link]()

(uint) 0 255 0

low

high (uint) 0 255 255

channelOptions (uint)
ARGB 7

grayScale (Boolean) true randomSeed


Alpha false

import [Link];
import [Link];
var myBitmap:BitmapData = new BitmapData(250, 250,false, 0xff000000);
[Link](500, 0, 255, [Link],false);
var image:Bitmap = new Bitmap(myBitmap);
addChild(image);

perlinNoise() perlinNoise()

perlinNoise()
Flash
Perlin

(Number) x
baseY (Number) y
numOctaves (uint) octave octave
baseX

474

randomSeed (int) noise()


[Link]()

stitch (Boolean) true

(Boolean) true
false

channelOptions (uint)channelOptions noise()



ARGB 7

grayScale

fractalNoise

(Boolean)grayScale noise()

true randomSeed
false

offsets (Array) octave x y


octave
null

150 x 150

BitmapData perlinNoise()

import [Link];
import [Link];
var myBitmapDataObject:BitmapData = new BitmapData(150, 150, false,
0x00FF0000);
var seed:Number = [Link]([Link]() * 100);
var channels:uint = [Link] | [Link]
[Link](100, 80, 6, seed, false, true, channels,
false, null);
var myBitmap:Bitmap = new Bitmap(myBitmapDataObject);
addChild(myBitmap);

475

scroll()
scroll() (x, y)


enterFrame

Perlin
scroll() enterFrame

import [Link];
import [Link];
var myBitmapDataObject:BitmapData = new BitmapData(1000, 1000, false,
0x00FF0000);
var seed:Number = [Link]([Link]() * 100);
var channels:uint = [Link] | [Link];
[Link](100, 80, 6, seed, false, true, channels,
false, null);
var myBitmap:Bitmap = new Bitmap(myBitmapDataObject);
myBitmap.x = -750;
myBitmap.y = -750;
addChild(myBitmap);
addEventListener(Event.ENTER_FRAME, scrollBitmap);
function scrollBitmap(event:Event):void
{
[Link](1, 1);
}

sprite
Flash
sprite
[Link]/go/learn_fl_bitmaps_cn

476

19

19

Flash Internet
Flash
ActionScript

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Flash (FLV) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .482
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .483
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .485
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .485
onCuePoint onMetaData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .486
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .492
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .492
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .496
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505

477

Adobe Flash Player ActionScript

Adobe Flash CS3 Professional Flash (FLV)


ActionScript

ActionScript

Video Video Video


NetStream ActionScript NetStream


NetStream
NetConnection

Camera Camera

Web
Adobe Macromedia Flash Media Server

FLV

478

Internet

Web


Internet

ActionScript
Flash ActionScript
Flash Player
Video

1.

Flash

2.
3.
4.
5.
6.

( ActionScript )
7.

479

8.

vid
vid

Video

9. >

SWF

1.

FLA

2. >
3. ActionScript

ActionScript
4.

ActionScript

5. >

Flash
VideoTest
ActionScript [Link]

6.
7.

Flash
>

53

Flash (FLV)
FLV Flash Player
QuickTime Windows Media Flash Video Encoder
Sorenson Squeeze FLV
Flash FLV FLV
FLV FLV
FLV

Flash
FLV

480

FLV Flash Flash


30 / (fps) 21 fps

Flash FLV

FLV Flash
CD-ROM FLV
Flash

FLV

Web FLV Web MIME


Web FLV MIME video/x-flv
504 FLV

Video
Video SWF
[Link]() Video HTTP
FLV Video

NetConnection

NetStream FLV Video

FLVPlayback

Video Video

Video [Link] [Link]


Video
339 371
403

Video

481


NetStream NetConnection
1.

NetConnection Adobe
Flash Media Server 2 Adobe Flex FLV NetConnection
connect() null HTTP FLV

var nc:NetConnection = new NetConnection();


[Link](null);

2.

NetStream NetConnection
FLV NetStream NetConnection
SWF [Link] FLV
var ns:NetStream = new NetStream(nc);
[Link](AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
[Link]("[Link]");
function asyncErrorHandler(event:AsyncErrorEvent):void
{
//
}

3.

Video Video attachNetStream()


NetStream addChild()

var vid:Video = new Video();


[Link](ns);
addChild(vid);

Flash

482

Player SWF [Link]

Web FLV Web MIME


Web FLV MIME video/x-flv
504 FLV


NetStream
pause()
resume()

seek()
togglePause()

stop()

play()

4 pauseBtnplayBtnstopBtn togglePauseBtn
var nc:NetConnection = new NetConnection();
[Link](null);
var ns:NetStream = new NetStream(nc);
[Link](AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
[Link]("[Link]");
function asyncErrorHandler(event:AsyncErrorEvent):void
{
//
}
var vid:Video = new Video();
[Link](ns);
addChild(vid);
[Link]([Link], pauseHandler);
[Link]([Link], playHandler);
[Link]([Link], stopHandler);
[Link]([Link], togglePauseHandler);
function pauseHandler(event:MouseEvent):void
{
[Link]();
}
function playHandler(event:MouseEvent):void
{
[Link]();
}
function stopHandler(event:MouseEvent):void
{

483

//
//
[Link]();
[Link](0);
}
function togglePauseHandler(event:MouseEvent):void
{
[Link]();
}

pauseBtn
playBtn

NetStream netStatus

[Link](NetStatusEvent.NET_STATUS, statusHandler);
function statusHandler(event:NetStatusEvent):void
{
trace([Link])
}

[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]

[Link] [Link]
switch

function statusHandler(event:NetStatusEvent):void
{
switch ([Link])
{
case "[Link]":
trace("Start [" + [Link](3) + " seconds]");
break;

484

case "[Link]":
trace("Stop [" + [Link](3) + " seconds]");
break;
}
}

netStatus (NetStatusEvent.NET_STATUS)

Flash Media Server NetConnection NetStream


(RTMP)
[Link]() RTMP URL rtmp://localhost/
appName/appInstance null Flash Media Server
[Link]() [Link]()
Flash Media
Server

FLV FLV
FLV FLV
Flash ActionScript FLV
FLV ActionScript

FLV

FLV FLV

FLV FLV
FLV

ActionScript ActionScript

1/10

FLV

FLV

485


ActionScript FLV
FLV
Flash
ActionScript onCuePoint

[Link]
486 onCuePoint onMetaData

onCuePoint onMetaData

onCuePoint onMetaData
Flash Player SWF
[Link] FLV
var nc:NetConnection = new NetConnection();
[Link](null);
var ns:NetStream = new NetStream(nc);
[Link](AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
[Link]("[Link]");
function asyncErrorHandler(event:AsyncErrorEvent):void
{
trace([Link]);
}
var vid:Video = new Video();
[Link](ns);
addChild(vid);

[Link] FLV asyncError


(AsyncErrorEvent.ASYNC_ERROR)
FLV
asyncError
FLV

486

#2095:
#2095:
#2095:
#2095:

[Link]
[Link]
[Link]
[Link]

onMetaData
onCuePoint
onCuePoint
onCuePoint

NetStream onMetaData onCuePoint

NetStream client

NetStream

NetStream

NetStream client

Object

this

NetStream client Object


client Object NetStream
onMetaData onCuePoint
Object asyncError
var nc:NetConnection = new NetConnection();
[Link](null);
var customClient:Object = new Object();
var ns:NetStream = new NetStream(nc);
[Link] = customClient;
[Link]("[Link]");
var vid:Video = new Video();
[Link](ns);
addChild(vid);

onMetaData onCuePoint

var customClient:Object = new Object();


[Link] = metaDataHandler;
function metaDataHandler(infoObject:Object):void
{
trace("metadata");
}

onMetaData metaDataHandler()
Flash Player onCuePoint

onCuePoint onMetaData

487


NetStream client CustomClient

var nc:NetConnection = new NetConnection();


[Link](null);
var ns:NetStream = new NetStream(nc);
[Link] = new CustomClient();
[Link]("[Link]");
var vid:Video = new Video();
[Link](ns);
addChild(vid);

CustomClient
package
{
public class CustomClient
{
public function onMetaData(infoObject:Object):void
{
trace("metadata");
}
}
}

CustomClient onMetaData
onCuePoint asyncError
(AsyncErrorEvent.ASYNC_ERROR) [Link] onCuePoint
CustomClient onCuePoint
asyncError

NetStream
CustomNetStream CustomNetStream

var ns:CustomNetStream = new CustomNetStream();


[Link]("[Link]");
var vid:Video = new Video();
[Link](ns);
addChild(vid);

488

CustomNetStream NetStream
NetConnection onMetaData onCuePoint
package
{
import [Link];
import [Link];
public class CustomNetStream extends NetStream
{
private var nc:NetConnection;
public function CustomNetStream()
{
nc = new NetConnection();
[Link](null);
super(nc);
}
public function onMetaData(infoObject:Object):void
{
trace("metadata");
}
public function onCuePoint(infoObject:Object):void
{
trace("cue point");
}
}
}

CustomNetStream onMetaData() onCuePoint()

package
{
import [Link];
import [Link];
public class CustomNetStream extends NetStream
{
private var nc:NetConnection;
public var onMetaData:Function;
public var onCuePoint:Function;
public function CustomNetStream()
{
onMetaData = metaDataHandler;
onCuePoint = cuePointHandler;
nc = new NetConnection();
[Link](null);
super(nc);
}
private function metaDataHandler(infoObject:Object):void
{
trace("metadata");
}

onCuePoint onMetaData

489

private function cuePointHandler(infoObject:Object):void


{
trace("cue point");
}
}
}

NetStream
NetStream onCuePoint onMetaData

var ns:DynamicCustomNetStream = new DynamicCustomNetStream();


[Link]("[Link]");
var vid:Video = new Video();
[Link](ns);
addChild(vid);

DynamicCustomNetStream
package
{
import [Link];
import [Link];
public dynamic class DynamicCustomNetStream extends NetStream
{
private var nc:NetConnection;
public function DynamicCustomNetStream()
{
nc = new NetConnection();
[Link](null);
super(nc);
}
}
}

DynamicCustomNetStream onMetaData onCuePoint


onMetaData onCuePoint

var ns:DynamicCustomNetStream = new DynamicCustomNetStream();


[Link] = metaDataHandler;
[Link] = cuePointHandler;
[Link]("[Link]
var vid:Video = new Video();
[Link](ns);
addChild(vid);
function metaDataHandler(infoObject:Object):void

490

{
trace("metadata");
}
function cuePointHandler(infoObject:Object):void
{
trace("cue point");
}

NetStream client this


client this Flash Player onMetaData()
onCuePoint()
var nc:NetConnection = new NetConnection();
[Link](null);
var ns:NetStream = new NetStream(nc);
[Link] = this;
[Link]("[Link]");
var vid:Video = new Video();
[Link](ns);
addChild(vid);

onMetaData onCuePoint
onMetaData() onCuePoint()

function onMetaData(infoObject:Object):void
{
trace("metadata");
}
function onCuePoint(infoObject:Object):void
{
trace("cue point");
}

onCuePoint onMetaData

491


for..in onCuePoint infoObject

var nc:NetConnection = new NetConnection();


[Link](null);
var ns:NetStream = new NetStream(nc);
[Link] = this;
[Link]("[Link]");
var vid:Video = new Video();
[Link](ns);
addChild(vid);
function onCuePoint(infoObject:Object):void
{
var key:String;
for (key in infoObject)
{
trace(key + ": " + infoObject[key]);
}
}

parameters:
name: point1
time: 0.418
type: navigation

onCuePoint onMetaData

onMetaData FLV FLV


FLV
FLV
var nc:NetConnection = new NetConnection();
[Link](null);
var ns:NetStream = new NetStream(nc);
[Link] = this;
[Link]("[Link]");
var vid:Video = new Video();

492

[Link](ns);
addChild(vid);
function onMetaData(infoObject:Object):void
{
var key:String;
for (key in infoObject)
{
trace(key + ": " + infoObject[key]);
}
}

FLV
width: 320
audiodelay: 0.038
canSeekToEnd: true
height: 213
cuePoints: ,,
audiodatarate: 96
duration: 16.334
videodatarate: 400
framerate: 15
videocodecid: 4
audiocodecid: 2

audiodatarate undefined

Object
function traceObject(obj:Object, indent:uint = 0):void
{
var indentString:String = "";
var i:uint;
var prop:String;
var val:*;
for (i = 0; i < indent; i++)
{
indentString += "\t";
}
for (prop in obj)
{
val = obj[prop];
if (typeof(val) == "object")
{
trace(indentString + " " + j + ": [Object]");
traceObject(val, indent + 1);
}
else

493

{
trace(indentString + " " + prop + ": " + val);
}
}
}

onMetaData() infoObject
width: 320
audiodatarate: 96
audiocodecid: 2
videocodecid: 4
videodatarate: 400
canSeekToEnd: true
duration: 16.334
audiodelay: 0.038
height: 213
framerate: 15
cuePoints: [Object]
0: [Object]
parameters: [Object]
lights: beginning
name: point1
time: 0.418
type: navigation
1: [Object]
parameters: [Object]
lights: middle
name: point2
time: 7.748
type: navigation
2: [Object]
parameters: [Object]
lights: end
name: point3
time: 16.02
type: navigation

494

onMetaData

audiocodecid

audiodatarate

audiodelay

FLV time 0 FLV

canSeekToEnd

FLV
true FLV
false

cuePoints

FLV
FLV

type navigation
event

name
time

parameters

duration

FLV

framerate

FLV

height

FLV

videocodecid

videodatarate

FLV

width

FLV

495

videocodecid

videocodecid

Sorenson H.263

SWF
7

VP6 SWF 8

Alpha VP6
SWF 8

audiocodecid

audiocodecid

ADPCM

mp3

Nellymoser 8kHz

Nellymoser

ActionScript
Camera ActionScript

Camera
Camera
Flash Media Server
Camera

Flash Player

Flash Player

496

Camera Camera
[Link]
name

NetConnection NetStream FLV


Flash Player
Camera
Camera
var cam:Camera = [Link]();
var vid:Video = new Video();
[Link](cam);
addChild(vid);

Camera Camera [Link]()

Flash Player
Flash Player
Flash Player

Camera
[Link]() Camera
Camera
Camera DisplayObject
2 3
attachCamera()

497


var cam:Camera = [Link]();
var vid:Video = new Video();
[Link](cam);
addChild(vid);

Flash

Player

Camera

[Link]

[Link]
if ([Link] > 0)
{
trace(" ");
}
else
{
var cam:Camera = [Link](); //
}

[Link]()
null Camera
[Link]()
var cam:Camera = [Link]();
if (cam == null)
{
trace(" ");
}
else
{
trace(" 1 ");
}

Camera DisplayObject addChild()


Video
Video attachCamera()

498

Flash Player

var cam:Camera = [Link]();


if (cam != null)
{
var vid:Video = new Video();
[Link](cam);
addChild(vid);
}

Flash Player
attachCamera() Flash Player Flash Player
Flash Player
Video Flash Player
Video
Flash Player Flash
Player Flash Player Flash Player

status
([Link])
var cam:Camera = [Link]();
if (cam != null)
{
[Link]([Link], statusHandler);
var vid:Video = new Video();
[Link](cam);
addChild(vid);
}
function statusHandler(event:StatusEvent):void
{
// Flash Player
//
trace([Link]); // [Link] [Link]
}

499

statusHandler()

statusHandler() event code


[Link] [Link] [Link]
Flash Player

function statusHandler(event:StatusEvent):void
{
switch ([Link])
{
case "[Link]":
trace(" ");
break;
case "[Link]":
trace(" ");
break;
}
}

Camera muted Flash Player


(true) (false)

function statusHandler(event:StatusEvent):void
{
if ([Link])
{
trace(" ");
}
else
{
trace(" ");
}
}

status


Video

500


Video 320 240
Camera Camera width
height Camera width
height Camera Camera
Video
var cam:Camera = [Link]();
if (cam != null)
{
var vid:Video = new Video([Link], [Link]);
[Link](cam);
addChild(vid);
}

getCamera() Camera null


Camera

var vid:Video;
var cam:Camera = [Link]();
if (cam == null)
{
trace(" ");
}
else
{
trace(" : " + [Link]);
[Link]([Link], statusHandler);
vid = new Video();
[Link](cam);
}
function statusHandler(event:StatusEvent):void
{
if ([Link])
{
trace(" ");
}
else
{
// Video
//
[Link] = [Link];
[Link] = [Link];
addChild(vid);
}
// status
[Link]([Link], statusHandler);
}

501


Camera Camera
Timer
var vid:Video;
var cam:Camera = [Link]();
var tf:TextField = new TextField();
tf.x = 300;
[Link] = [Link];
addChild(tf);
if (cam != null)
{
[Link]([Link], statusHandler);
vid = new Video();
[Link](cam);
}
function statusHandler(event:StatusEvent):void
{
if (![Link])
{
[Link] = [Link];
[Link] = [Link];
addChild(vid);
[Link]();
}
[Link]([Link], statusHandler);
}
var t:Timer = new Timer(100);
[Link]([Link], timerHandler);
function timerHandler(event:TimerEvent):void
{
[Link] = "";
[Link]("activityLevel: " + [Link] + "\n");
[Link]("bandwidth: " + [Link] + "\n");
[Link]("currentFPS: " + [Link] + "\n");
[Link]("fps: " + [Link] + "\n");
[Link]("keyFrameInterval: " + [Link] + "\n");
[Link]("loopback: " + [Link] + "\n");
[Link]("motionLevel: " + [Link] + "\n");
[Link]("motionTimeout: " + [Link] + "\n");
[Link]("quality: " + [Link] + "\n");
}

1/10 100 Timer timer timerHandler()

502


Video Camera Flash Media
Server
Video on Demand Web
mp3
Flash Media Server [Link]

Flash Player FLV


Flash Player 7 Sorenson Spark FLV Flash Player 8
Flash Professional 8 Sorenson Spark On2 VP6 FLV
On2 VP6 Alpha Flash Player FLV

Sorenson Spark

On2 VP6

SWF

Flash Player

6 7 8

7, 8

8*

SWF FLV Flash Player 8 SWF


On2 VP6 Flash Player 8 SWF
Flash Player 8 On2 VP6

503

FLV
FLV FLV Internet
(MIME) Internet ASCII Web
MIME
Web FLV
Web MIME Web FLV
MIME video/x-flv FLV

Mime video/x-flv
.flv

FLV /

[Link]/go/flashfileformat_cn

Microsoft Microsoft Internet (IIS) 6.0 Web


IIS Flash
Windows 2003 Web IIS 6.0 MIME
FLV
FLV SWF Microsoft Windows
Server 2003 SWF FLV
Windows Server 2003
FLV Flash Adobe Macromedia Flash Video Kit
for Dreamweaver MX 2004

Microsoft Windows 2003 Microsoft IIS Server 6.0


FLV [Link]/go/tn_19439_cn

504

Macintosh FLV
Apple Macintosh (/)
FLV CD-ROM

Flash Player

Macintosh FLV (:)


(/)

myDrive/myFolder/[Link]
(Mac OS)

myDrive:myFolder:[Link]
Macintosh CD-ROM Mac OS CD-ROM
FLV [Link]/go/3121b301_cn

ActionScript 3.0

FLV

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/VideoJukebox

[Link]

[Link]

Flash

[Link]

505


[Link] XML
URLLoader URLRequest
uldr = new URLLoader();
[Link]([Link], xmlCompleteHandler);
[Link](new URLRequest(PLAYLIST_XML_URL));

VideoJukebox
XML xmlCompleteHandler()
XML
private function xmlCompleteHandler(event:Event):void
{
playlist = XML([Link]);
videosXML = [Link];
main();
}

XML XML videosXML


[Link]

XMLList

<videos>
<video url="video/caption_video.flv" />
<video url="video/[Link]" />
<video url="video/[Link]" />
</videos>

xmlCompleteHandler() main()
FLV NetConnection NetStream

5 Button
playButton pauseButton stopButton backButton forwardButton
Button click

[Link]([Link], buttonClickHandler);
[Link]([Link], buttonClickHandler);
[Link]([Link], buttonClickHandler);
[Link]([Link], buttonClickHandler);
[Link]([Link], buttonClickHandler);

506

buttonClickHandler() switch
private function buttonClickHandler(event:MouseEvent):void
{
switch ([Link])
{
case playButton:
[Link]();
break;
case pauseButton:
[Link]();
break;
case stopButton:
[Link]();
[Link](0);
break;
case backButton:
playPreviousVideo();
break;
case forwardButton:
playNextVideo();
break;
}
}

Slider volumeSlider
liveDragging true change

[Link] = [Link];
[Link] = 0;
[Link] = 1;
[Link] = 0.1;
[Link] = [Link];
[Link] = true;
[Link]([Link], volumeChangeHandler);

ProgressBar positionBar mode


manual
[Link] = [Link];

Label positionLabel Label

507


Flash Player NetStream client
onMetaData()
client = new Object();
[Link] = metadataHandler;
metadataHandler()

meta

positionBar metadataHandler()
private function metadataHandler(metadataObj:Object):void
{
meta = metadataObj;
[Link] = [Link];
[Link] = [Link];
[Link](vid.x, vid.y + [Link]);
[Link] = [Link];
}

Flash
Flash NetConnection NetStream
NetConnection null connect() null
Flash Player Flash Media Server
NetConnection NetStream netStatus
client client
nc = new NetConnection();
[Link](null);
ns = new NetStream(nc);
[Link](NetStatusEvent.NET_STATUS, netStatusHandler);
[Link] = client;

netStatusHandler()
netStatusHandler()
private function netStatusHandler(event:NetStatusEvent):void
{
try
{
switch ([Link])
{
case "[Link]":
[Link]();
break;

508

case "[Link]":
case "[Link]":
[Link]();
playNextVideo();
break;
}
}
catch (error:TypeError)
{
//
}
}

info code [Link]


[Link] [Link]
Timer
Timer

Timer positionBar ProgressBar setProgress()


positionLabel
Label
private function timerHandler(event:TimerEvent):void
{
try
{
[Link]([Link], [Link]);
[Link] = [Link](1) + " of "
[Link](1) + " seconds";
}
catch (error:Error)
{
//
}
}

509


NetStream soundTransform
volumeSlider Slider
Slider SoundTransform NetStream
soundTransform
private function volumeChangeHandler(event:SliderEvent):void
{
[Link] = [Link];
[Link] = volumeTransform;
}

XMLList URL
private function getVideo():String
{
return videosXML[idx].@url;
}
playVideo()

NetStream play()

private function playVideo():void


{
var url:String = getVideo();
[Link](url);
}
playPreviousVideo() playVideo()

private function playPreviousVideo():void


{
if (idx > 0)
{
idx--;
playVideo();
[Link] = true;
}
}

510

playNextVideo() playVideo()
Video clear()
visible false
private function playNextVideo():void
{
if (idx < ([Link]() - 1))
{
idx++;
playVideo();
[Link] = true;
}
else
{
idx++;
[Link]();
[Link] = false;
}
}

511

512

20

20

ActionScript

Internet mp3

SWF

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .525
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .526
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .528
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .532
Podcast Player. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .535

513

Adobe Flash Player ActionScript

ActionScript

ActionScript Flash Player


Flash Player ActionScript
mp3 SWF SWF

ActionScript 3.0
Flash Player mp3
WAV AIFF
ActionScript [Link] Sound
Flash
Player SoundChannel

SoundChannel SoundChannel
SoundChannel
SoundMixer
ActionScript
516

514

mp3

mp3

ID3

(Amplitude)

(Bit rate) mp3


(kbps)

(Buffering)

mp3MPEG-1 Audio Layer 3 (mp3)


(Panning)
(Peak)
(Sampling rate)
44.1 kHz 44,100
(Streaming)

(Volume)

(Waveform)

ActionScript

1.

Flash

2.
3.

515

4.
var req:URLRequest = new URLRequest("click.mp3");
var s:Sound = new Sound(req);

click.mp3
mp3 mp3 Flash
mp3 click.mp3
mp3
5. >

SWF

trace()

Flash Player
53

SWF

Flash Media

Server

ActionScript 3.0 Flash Player mp3


WAV AIFF
Adobe Flash CS3 Professional WAV AIFF mp3
SWF Flash
Flash

516

ActionScript 3.0 [Link]

[Link]

Sound

[Link]

Sound
SoundChannel SoundChannel

SoundChannel

[Link]

SoundLoaderContext
Flash Player
SoundLoaderContext
[Link]()

[Link]

SoundMixer
SoundMixer
SoundMixer
SoundChannel

[Link]

SoundTransform
SoundTransform SoundChannel
SoundMixer Microphone

[Link].ID3Info

ID3Info mp3
ID3

[Link]

Microphone

Microphone

Sound SoundChannel
SoundMixer SoundChannel

Sound SoundChannel SoundMixer Flash


Media Server

Sound Sound
Sound

Sound
var req:URLRequest = new URLRequest("click.mp3");
var s:Sound = new Sound(req);

517

Sound() URLRequest URLRequest


Sound

Sound
Sound

open ([Link])

progress ([Link])

id3 (Event.ID3)

mp3 ID3

complete ([Link])

ioError (IOErrorEvent.IO_ERROR)

import [Link];
import [Link];
import [Link];
var s:Sound = new Sound();
[Link]([Link], onSoundLoaded);
var req:URLRequest = new URLRequest("bigSound.mp3");
[Link](req);
function onSoundLoaded(event:Event):void
{
var localSound:Sound = [Link] as Sound;
[Link]();
}

Sound URLRequest
Sound [Link]
onSoundLoaded() URLRequest
[Link]()
onSoundLoaded() Event
Sound play()

518

Sound


Flash Player

Sound
[Link] [Link]

import
import
import
import

[Link];
[Link];
[Link];
[Link];

var s:Sound = new Sound();


[Link]([Link], onLoadProgress);
[Link]([Link], onLoadComplete);
[Link](IOErrorEvent.IO_ERROR, onIOError);
var req:URLRequest = new URLRequest("bigSound.mp3");
[Link](req);
function onLoadProgress(event:ProgressEvent):void
{
var loadedPct:uint =
[Link](100 * ([Link] / [Link]));
trace("The sound is " + loadedPct + "% loaded.");
}
function onLoadComplete(event:Event):void
{
var localSound:Sound = [Link] as Sound;
[Link]();
}
function onIOError(event:IOErrorEvent)
{
trace("The sound could not be loaded: " + [Link]);
}

Sound [Link]
[Link] [Link]()
[Link] onSoundLoadProgress()
ProgressEvent bytesLoaded bytesTotal
Sound bytesLoaded bytesTotal
bytesLoaded bytesTotal
Adobe Flex 2 Flash

519


Sound Event.IO_ERROR
onIOError()



SWF
SWF
SWF

Flash
Flash
ActionScript
ActionScript Flash
Flash Flash
Flash
1. > >
2.

ActionScript

3.

ActionScript

DrumSound.mp3 DrumSound
ActionScript
[Link]

4.

[Link]
5.

ActionScript
DrumSound

var drum:DrumSound = new DrumSound();


var channel:SoundChannel = [Link]();

DrumSound [Link] Sound


play()

520

Flash Player
bufferTime 5000
Flash Player 5000
[Link] 1000
[Link]

bufferTime
[Link]

SoundLoaderContext bufferTime
[Link]()
import [Link];
import [Link];
import [Link];
var s:Sound = new Sound();
var req:URLRequest = new URLRequest("bigSound.mp3");
var context:SoundLoaderContext = new SoundLoaderContext(8000, true);
[Link](req, context);
[Link]();

Flash Player

Flash Player [Link]

Sound [Link]()
var snd:Sound = new Sound(new URLRequest("smallSound.mp3"));
[Link]();

ActionScript 3.0

521

SoundChannelSoundMixer SoundTransform

SoundChannel [Link]

[Link]() SoundChannel
[Link]() startTime
[Link]() loops

startTime loops [Link]()

var snd:Sound = new Sound(new URLRequest("repeatingSound.mp3"));


[Link](1000, 3);


ActionScript

var snd:Sound = new Sound(new URLRequest("bigSound.mp3"));


var channel:SoundChannel = [Link]();

[Link]

var pausePosition:int = [Link];


[Link]();

channel = [Link](pausePosition);

522

SoundChannel
Event.SOUND_COMPLETE
import [Link];
import [Link];
import [Link];
var snd:Sound = new Sound("smallSound.mp3");
var channel:SoundChannel = [Link]();
[Link](Event.SOUND_COMPLETE, onPlaybackComplete);
public function onPlaybackComplete(event:Event)
{
trace(The sound has finished playing.);
}

SoundChannel

[Link]

var playbackPercent:uint = 100 * ([Link] / [Link]);

[Link]

Sound bytesLoaded bytesTotal

var estimatedLength:int =
[Link]([Link] / ([Link] / [Link]));
var playbackPercent:uint = 100 * ([Link] / estimatedLength);

Event.ENTER_FRAME

import [Link];
import [Link];
import [Link];
var snd:Sound = new Sound();
var req:URLRequest = new
URLRequest("[Link]
[Link](req);
var channel:SoundChannel;
channel = [Link]();

523

addEventListener(Event.ENTER_FRAME, onEnterFrame);
[Link](Event.SOUND_COMPLETE, onPlaybackComplete);
function onEnterFrame(event:Event):void
{
var estimatedLength:int =
[Link]([Link] / ([Link] / [Link]));
var playbackPercent:uint =
[Link](100 * ([Link] / estimatedLength));
trace("Sound playback is " + playbackPercent + "% complete.");
}
function onPlaybackComplete(event:Event)
{
trace("The sound has finished playing.");
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}

[Link]() SoundChannel
channel Event.ENTER_FRAME
SoundChannel
Event.SOUND_COMPLETE
onEnterFrame() onEnterFrame()

onPlaybackComplete() Event.ENTER_FRAME

Event.ENTER_FRAME
[Link]
159


SoundChannel [Link]()

[Link]()

524


Flash Player

Flash Player
649 Flash Player
id3 [Link]()

SWF

checkPolicyFile SoundLoaderContext
[Link]() checkPolicyFile true Flash Player

SWF SWF Sound


id3 [Link]()

SoundChannel [Link]()

[Link]()

[Link]()
[Link]() true
[Link]()
[Link]()

FLA

Flash

525


SoundChannel mp3
SoundChannel
SoundChannel leftPeak rightPeak

SoundChannel SoundMixer

SoundChannel pan
pan -1 1 -1
1 -1 1
0
volume 0.6 pan -1 SoundTransform
SoundTransform play()
SoundTransform SoundChannel
var snd:Sound = new Sound(new URLRequest("bigSound.mp3"));
var trans:SoundTransform = new SoundTransform(0.6, -1);
var channel:SoundChannel = [Link](0, 1, trans);

SoundTransform pan
volume SoundChannel soundTransform
SoundMixer soundTransform

[Link] = new SoundTransform(1, -1);

SoundTransform Microphone 532


Sprite SimpleButton

import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];

var snd:Sound = new Sound();


var req:URLRequest = new URLRequest("bigSound.mp3");
[Link](req);
var panCounter:Number = 0;
var trans:SoundTransform;

526

trans = new SoundTransform(1, 0);


var channel:SoundChannel = [Link](0, 1, trans);
[Link](Event.SOUND_COMPLETE, onPlaybackComplete);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
[Link] = [Link](panCounter);
[Link] = trans; // or [Link] = trans;
panCounter += 0.05;
}
function onPlaybackComplete(event:Event):void
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}

volume 1 pan 0
SoundTransform
[Link]() SoundTransform
onEnterFrame() onEnterFrame() [Link]()
-1 1 [Link]
SoundTransform pan soundTransform
SoundTransform
mp3 bigSound.mp3

SoundMixer soundTransform
SoundChannel

mp3

ID3
mp3 ID3 Sound mp3
ID3 Event.ID3
Event.ID3 Sound.id3
ID3
import [Link];
import [Link].ID3Info;
import [Link];

527

var s:Sound = new Sound();


[Link](Event.ID3, onID3InfoReceived);
[Link]("mySound.mp3");
function onID3InfoReceived(event:Event)
{
var id3:ID3Info = [Link].id3;
trace("Received ID3 Info:");
for (var propName:String in id3)
{
trace(propName + " = " + id3[propName]);
}
}

Sound Event.ID3 ID3


onID3InfoReceived() onID3InfoReceived() Event
Sound Sound id3

[Link]()
SoundChannel [Link]()
SoundChannel
ByteArray 512
-1 1
256

FFTMode true [Link]()



(FFT) 0 1.414
2

528

FFTMode true false computeSpectrum()

computeSpectrum()
stretchFactor
computeSpectrum() stretchFactor 0
44.1 kHz stretchFactor 1
1 22.05 kHz 2 11.025 kHz
stretchFactor computeSpectrum()
256
[Link]()

RTMP SoundMixer
[Link]()

[Link]() [Link]()
525
671

529


[Link]()

import
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

const PLOT_HEIGHT:int = 200;


const CHANNEL_LENGTH:int = 256;
var snd:Sound = new Sound();
var req:URLRequest = new URLRequest("bigSound.mp3");
[Link](req);
var channel:SoundChannel;
channel = [Link]();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
[Link](Event.SOUND_COMPLETE, onPlaybackComplete);
var bytes:ByteArray = new ByteArray();
function onEnterFrame(event:Event):void
{
[Link](bytes, false, 0);
var g:Graphics = [Link];
[Link]();
[Link](0, 0x6600CC);
[Link](0x6600CC);
[Link](0, PLOT_HEIGHT);
var n:Number = 0;
// left channel
for (var i:int = 0; i < CHANNEL_LENGTH; i++)
{
n = ([Link]() * PLOT_HEIGHT);
[Link](i * 2, PLOT_HEIGHT - n);
}
[Link](CHANNEL_LENGTH * 2, PLOT_HEIGHT);
[Link]();
// right channel
[Link](0, 0xCC0066);

530

[Link](0xCC0066, 0.5);
[Link](CHANNEL_LENGTH * 2, PLOT_HEIGHT);
for (i = CHANNEL_LENGTH; i > 0; i--)
{
n = ([Link]() * PLOT_HEIGHT);
[Link](i * 2, PLOT_HEIGHT - n);
}
[Link](0, PLOT_HEIGHT);
[Link]();
}
function onPlaybackComplete(event:Event)
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}

onEnterFrame()
Event.ENTER_FRAME onEnterFrame() [Link]()
bytes ByteArray
API for 256
[Link]()
for 256

531


Microphone
Flash Media Server

Microphone [Link]()
Microphone
var mic:Microphone = [Link]();

[Link]()

[Link]
index
[Link]()
[Link]
[Link]()

names getMicrophone() null


[Link]() Flash Player Flash
Player Flash Player
StatusEvent
StatusEvent code
import [Link];
var mic:Microphone = [Link]();
[Link]([Link], [Link]);
function onMicStatus(event:StatusEvent):void
{
if ([Link] == "[Link]")
{
trace("Microphone access was allowed.");
}
else if ([Link] == "[Link]")
(
trace("Microphone access was denied.");
}
}

532

[Link] [Link]
[Link]

[Link] true
false StatusEvent Microphone muted
[Link] [Link]

true [Link]()

true
[Link]()
Adobe [Link](true)
[Link](true)

var mic:Microphone = [Link]();


[Link](true);
[Link](true);

[Link]
0 100 0 100 50 1 0
0 50

[Link] (kHz)
8 kHz
[Link] 8 kHz [Link]
11 11 kHz 22 22 kHz

533


Flash Player
Flash Player
ActivityEvent

Microphone
0 100

activityLevel

silenceLevel [Link]
silenceLevel

0 100 10

silenceTimeout

[Link] silenceTimeout
2000
[Link] [Link]

[Link]()

[Link]()
silenceLevel Flash Player
silenceLevel 100

Microphone

import flash,[Link];
import flash,[Link];
import [Link];
var deviceArray:Array = [Link];
trace("Available sound input devices:");
for (var i:int = 0; i < [Link]; i++)
{
trace("
" + deviceArray[i]);
}
var mic:Microphone = [Link]();
[Link] = 60;
[Link] = 11;
[Link](true);
[Link](true);
[Link](5, 1000);
[Link]([Link], [Link]);
[Link]([Link], [Link]);
var micDetails:String = "Sound input device name: " + [Link] + '\n';

534

micDetails += "Gain: " + [Link] + '\n';


micDetails += "Rate: " + [Link] + " kHz" + '\n';
micDetails += "Muted: " + [Link] + '\n';
micDetails += "Silence level: " + [Link] + '\n';
micDetails += "Silence timeout: " + [Link] + '\n';
micDetails += "Echo suppression: " + [Link] + '\n';
trace(micDetails);
function onMicActivity(event:ActivityEvent):void
{
trace("activating=" + [Link] + ", activityLevel=" +
[Link]);
}
function onMicStatus(event:StatusEvent):void
{
trace("status: level=" + [Link] + ", code=" + [Link]);
}

trace

ActionScript

Flash Media Server

Microphone NetStream
Flash Flex
MovieClip Video
[Link] Flash Media Server

Podcast Player
Internet

mp3
mp3

Podcast Player

535

Podcast Player ActionScript

RSS XML

SoundFacade

[Link]/go/learn_programmingAS3samples_flash_cn Podcast Player


Samples/PodcastPlayer

[Link]

Flex (MXML) Flash (FLA)

[Link]
[Link]

RSSChannel RSSItem

[Link]

RSS ActionScript

[Link]

RSS ActionScript

[Link]

ActionScript Sound
SoundChannel

[Link]

URL ActionScript

[Link]

XML
RSS

RSS
Podcast Player
1. XML
2. RSS

URLLoader
Podcast Player URLLoader [Link]
XML RSS
URLLoader URL RSS

536

SoundFacade
ActionScript 3.0

SoundFacade

Sound SoundLoaderContext SoundMixer

Sound SoundChannel

SoundChannel
SoundFacade ActionScript Sound

Sound

SoundFacade()
public class
{
public var
public var
public var
public var
public
public
public
public
public
public

var
var
var
var
var
var

SoundFacade extends EventDispatcher


s:Sound;
sc:SoundChannel;
url:String;
bufferTime:int = 1000;
isLoaded:Boolean = false;
isReadyToPlay:Boolean = false;
isPlaying:Boolean = false;
isStreaming:Boolean = true;
autoLoad:Boolean = true;
autoPlay:Boolean = true;

public var pausePosition:int = 0;


public static const PLAY_PROGRESS:String = "playProgress";
public var progressInterval:int = 1000;
public var playTimer:Timer;
public function SoundFacade(soundUrl:String, autoLoad:Boolean = true,
autoPlay:Boolean = true, streaming:Boolean = true,
bufferTime:int = -1):void
{
[Link] = soundUrl;
//
[Link] = autoLoad;
[Link] = autoPlay;
[Link] = streaming;
// bufferTime
if (bufferTime < 0)

Podcast Player

537

{
bufferTime = [Link];
}
// 0 30
[Link] = [Link]([Link](0, bufferTime), 30000);
if (autoLoad)
{
load();
}
}

SoundFacade EventDispatcher
Sound SoundChannel URL
bufferTime

autoLoad

autoPlay

streaming

bufferTime
bufferTime

-1 bufferTime

bufferTime [Link]
[Link]
autoLoad true load()

public function load():void


{
if ([Link])
{
[Link]();
[Link]();
}
[Link] = false;
this.s = new Sound();
[Link]([Link], onLoadProgress);
[Link]([Link], onLoadOpen);
[Link]([Link], onLoadComplete);
[Link](Event.ID3, onID3);
[Link](IOErrorEvent.IO_ERROR, onIOError);
[Link](SecurityErrorEvent.SECURITY_ERROR, onIOError);
var req:URLRequest = new URLRequest([Link]);

538

var context:SoundLoaderContext = new SoundLoaderContext([Link],


true);
[Link](req, [Link]);
}

Sound
Sound SoundLoaderContext bufferTime
url SoundFacade
load()

url load()

SoundFacade

public function onLoadOpen(event:Event):void


{
if ([Link])
{
[Link] = true;
if (autoPlay)
{
[Link]();
}
}
[Link]([Link]());
}
public function onLoadProgress(event:ProgressEvent):void
{
[Link]([Link]());
}
public function onLoadComplete(event:Event):void
{
[Link] = true;
[Link] = true;
[Link]([Link]());
if (autoPlay && !isPlaying)
{
play();
}
}

onLoadOpen()
onLoadComplete() isReadyToPlay true isReadyToPlay

SoundChannel play()

Podcast Player

539

onLoadProgress() ProgressEvent
SoundFacade
onLoadComplete() play()
play()
public function play(pos:int = 0):void
{
if (![Link])
{
if ([Link])
{
[Link] = [Link](pos);
[Link](Event.SOUND_COMPLETE, onPlayComplete);
[Link] = true;
[Link] = new Timer([Link]);
[Link]([Link], onPlayTimer);
[Link]();
}
}
}

play() [Link]() SoundChannel


sc play() Timer

Timer
SoundFacade Timer

[Link]() Timer
TimerEvent onPlayTimer()

TimerEvent

public function onPlayTimer(event:TimerEvent):void


{
var estimatedLength:int =
[Link]([Link] / ([Link] / [Link]));
var progEvent:ProgressEvent =
new ProgressEvent(PLAY_PROGRESS, false, false, [Link],
estimatedLength);
[Link](progEvent);
}
onPlayTimer() 523
SoundFacade.PLAY_PROGRESS ProgressEvent
bytesLoaded SoundChannel bytesTotal

540


[Link]() pos
pos
[Link]() pos
public function stop(pos:int = 0):void
{
if ([Link])
{
[Link] = pos;
[Link]();
[Link]();
[Link] = false;
}
}

[Link]() pausePosition

[Link]() [Link]()
[Link]() [Link]() pos
public function pause():void
{
stop([Link]);
}
public function resume():void
{
play([Link]);
}
pause() [Link] play()
pausePosition resume() pausePosition

Podcast Player
Podcast Player

SoundFacade

SharedObject

RSS

Podcast Player

541

mp3

[Link]

542

Internet

API

21

21

ActionScript 3.0

WordSearch

10

ActionScript 3.0 267

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .543
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .545
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
WordSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .552


ActionScript 3.0

InteractiveObject DisplayObject
InteractiveObject
SimpleButtonSpriteTextField Flash Flex
InteractiveObject

543

(Character code)
D d

(Context menu)

(Focus)

(Key

code)

ActionScript
InteractiveObject
Adobe Flash CS3 Professional
ActionScript Flash Player

1. Flash
2.
3.
4.

5.

myDisplayObject myDisplayObject

544

6. >

InteractiveObject

function reportKeyDown(event:KeyboardEvent):void
{
trace("Key Pressed: " + [Link]([Link]) +
" (character code: " + [Link] + ")");
}
[Link](KeyboardEvent.KEY_DOWN, reportKeyDown);

Ctrl

TextField
Shift TextField
tf TextField
[Link] = true;
[Link] = "input";
[Link](KeyboardEvent.KEY_DOWN,reportKeyDown);
[Link](KeyboardEvent.KEY_UP,reportKeyUp);
function reportKeyDown(event:KeyboardEvent):void
{
trace("Key Pressed: " + [Link]([Link]) +
" (key code: " + [Link] + " character code: "
+ [Link] + ")");
if ([Link] == [Link]) [Link] = 0xFF0000;
}
function reportKeyUp(event:KeyboardEvent):void
{
trace("Key Released: " + [Link]([Link]) +
" (key code: " + [Link] + " character code: " +
[Link] + ")");
if ([Link] == [Link])
{
[Link] = 0x000000;
}
}

545

TextField textInput
447

keyCode charCode
keyCode charCode
UTF-8 ASCII
1
1 1 !
R r

ASCII 593 C

Keyboard keyCode
Shift [Link]

KeyboardEvent

addEventListener()
tf container

[Link](KeyboardEvent.KEY_DOWN,reportKeyDown);
[Link] = true;
[Link] = "input";
[Link](KeyboardEvent.KEY_DOWN,reportKeyDown);
function reportKeyDown(event:KeyboardEvent):void
{
trace([Link] + " hears key press: " +
[Link]([Link]) + " (key code: " +
[Link] + " character code: " + [Link] + ")");
}

TextField
reportKeyDown() container

546

Web Adobe Flash Player Microsoft


Internet Explorer Ctrl+W SWF

SWF
InteractiveObject Sprite MovieClip

square
Sprite square Stage

Stage

var square:Sprite = new Sprite();


[Link](0xFF0000);
[Link](0,0,100,100);
[Link]();
[Link]([Link], reportClick);
square.x =
square.y = 50;
addChild(square);
[Link]([Link], reportClick);
function reportClick(event:MouseEvent):void
{
trace([Link]() +
" dispatches [Link] coords [" +
[Link] + "," + [Link] + "] Stage coords [" +
[Link] + "," + [Link] + "]");
}

localX localY
square
[0,0] square stageX stageY
[50,50] square

MouseEvent altKeyctrlKey shiftKey


Alt Ctrl Shift

547

import [Link];
import [Link];
var circle:Sprite = new Sprite();
[Link](0xFFCC00);
[Link](0, 0, 40);
var target1:Sprite = new Sprite();
[Link](0xCCFF00);
[Link](0, 0, 100, 100);
[Link] = "target1";
var target2:Sprite = new Sprite();
[Link](0xCCFF00);
[Link](0, 200, 100, 100);
[Link] = "target2";
addChild(target1);
addChild(target2);
addChild(circle);
[Link](MouseEvent.MOUSE_DOWN, mouseDown)
function mouseDown(event:MouseEvent):void
{
[Link]();
}
[Link](MouseEvent.MOUSE_UP, mouseReleased);
function mouseReleased(event:MouseEvent):void
{
[Link]();
trace([Link]);
}

341

548



[Link]() [Link]()
MouseEvent.MOUSE_MOVE
stageX stageY
var cursor:Sprite = new Sprite();
[Link](0x000000);
[Link](0,0,20);
[Link]();
addChild(cursor);
[Link](MouseEvent.MOUSE_MOVE,redrawCursor);
[Link]();
function redrawCursor(event:MouseEvent):void
{
cursor.x = [Link];
cursor.y = [Link];
}

InteractiveObject SWF


Stage
showDefaultContextMenu false
ContextMenu
hideBuiltInItems() DisplayObject contextMenu

var square:Sprite = new Sprite();


[Link](0x000000);
[Link](0,0,100,100);
[Link]();
square.x =
square.y = 10;
addChild(square);
var menuItem:ContextMenuItem = new ContextMenuItem("Change Color");
[Link](ContextMenuEvent.MENU_ITEM_SELECT,changeColor);
var customContextMenu:ContextMenu = new ContextMenu();
[Link]();

549

[Link](menuItem);
[Link] = customContextMenu;
function changeColor(event:ContextMenuEvent):void
{
[Link] = getRandomColor();
}
function getRandomColor():ColorTransform
{
return new ColorTransform([Link](), [Link](),
[Link](),1,([Link]() * 512) - 255,
([Link]() * 512) -255, ([Link]() * 512) - 255, 0);
}

focus true tabEnabled true


Tab tabEnabled false

SimpleButton true

true

buttonMode true Sprite

MovieClip true

FocusEvent.FOCUS_IN FocusEvent.FOCUS_OUT
sprite
InteractiveObject Tab

Flash
SWF Flash

var rows:uint = 10;


var cols:uint = 10;
var rowSpacing:uint = 25;
var colSpacing:uint = 25;
var i:uint;
var j:uint;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
createSquare(j * colSpacing, i * rowSpacing, (i * cols) + j);
}
}

550

function createSquare(startX:Number, startY:Number, tabNumber:uint):void


{
var square:Sprite = new Sprite();
[Link](0x000000);
[Link](0, 0, colSpacing, rowSpacing);
[Link]();
square.x = startX;
square.y = startY;
[Link] = true;
[Link] = tabNumber;
[Link](FocusEvent.FOCUS_IN, changeColor);
addChild(square);
}
function changeColor(event:FocusEvent):void
{
[Link] = getRandomColor();
}
function getRandomColor():ColorTransform
{
//
var red:Number = ([Link]() * 512) - 255;
var green:Number = ([Link]() * 512) - 255;
var blue:Number = ([Link]() * 512) - 255;
// ColorTransform
return new ColorTransform(1, 1, 1, 1, red, green, blue, 0);
}

551

WordSearch

ActionScript 3.0

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/WordSearch WordSearch

[Link]

[Link]

Flash

[Link]

[Link]
words loadDictionary()
split()
10
dictionaryLoaded()
words = [Link]([Link](10));

Button

[Link] setupUI()

[Link]([Link],submitWord);
[Link]([Link],clearWord);

552


generateBoard()

private function generateBoard(startX:Number,


startY:Number,
totalRows:Number,
totalCols:Number,
buttonSize:Number):void
{
buttons = new Array();
var colCounter:uint;
var rowCounter:uint;
for (rowCounter = 0; rowCounter < totalRows; rowCounter++)
{
for (colCounter = 0; colCounter < totalCols; colCounter++)
{
var b:Button = new Button();
b.x = startX + (colCounter*buttonSize);
b.y = startY + (rowCounter*buttonSize);
[Link]([Link], letterClicked);
[Link] = getRandomLetter().toUpperCase();
[Link](buttonSize,buttonSize);
[Link] = "buttonRow"+rowCounter+"Col"+colCounter;
addChild(b);
[Link](b);
}
}
}

[Link] for
Button

WordSearch

553

isLegalContinuation()

private function isLegalContinuation(prevButton:Button,


currButton:Button):Boolean
{
var currButtonRow:Number = Number([Link]([Link].
indexOf("Row") + 3));
var currButtonCol:Number =
Number([Link]([Link]("Col") + 3));
var prevButtonRow:Number =
Number([Link]([Link]("Row") + 3));
var prevButtonCol:Number =
Number([Link]([Link]("Col") + 3));
return ((prevButtonCol == currButtonCol && [Link](prevButtonRow currButtonRow) <= 1) ||
(prevButtonRow == currButtonRow && [Link](prevButtonCol currButtonCol) <= 1));
}

String charAt() indexOf()

isLegalContinuation() true

return ([Link](prevButtonRow - currButtonRow) <= 1) &&


[Link](prevButtonCol - currButtonCol) <= 1));

searchForWord()

private function searchForWord(str:String):Number


{
if (words && str)
{
var i:uint = 0
for (i = 0; i < [Link]; i++)
{
var thisWord:String = words[i];
if (str == words[i])
{
return i;

554

}
}
return -1;
}
else
{
trace("WARNING: cannot find words, or string supplied is null");
}
return -1;
}

submitWord()

TOTAL_TIME
PERCENT_VOWELS

WordSearch

555

556

22

22

SWF Adobe Flash Player 9


Java Flash Player
FileReference FileReferenceList

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .558
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .566
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .579
Telnet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .589
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .592

557

ActionScript
XML [Link] Internet
URL Flash Player
ActionScript 3.0 URLLoader URLRequest

- URLVariables URLLoader
URLRequest XML XML
XMLDocument [Link]() XML
ActionScript URLVariables XML

[Link] FileReference
Socket XMLSocket
NetConnection NetStream
Flash Flash Media Server Flash Remoting

[Link] LocalConnection
SWF SharedObject

ActionScript

SWF

XML

558

(External data) SWF


SWF

URL (URL-encoded variable)URL


name=value
- and
variable1=value1&variable2=value2

MIME (MIME type) Internet

Web Flash Player


HTTP Internet

(Request method) Flash Player Web


HTTP Web
GET POST
ActionScript

(Socket connection)

(Upload)

(Download)

trace()

SWF

1.

Flash

Flash

2.

3.
4. >

SWF

559

Flash

1.

Flash

2.

ActionScript Flash
UploadTest
ActionScript [Link]

3.

ActionScript

4.
5.
6.

Flash
ActionScript
>

Web

ActionScript 3.0
Web
ActionScript

URLLoader URLVariables
ActionScript 3.0 URLLoader URLVariables URLLoader
URL URL URLLoader
XML ActionScript URLLoader
ActionScript 3.0 completehttpStatus
ioErroropenprogress securityError ActionScript 2.0
[Link] [Link] [Link]
10

560

ActionScript XML LoadVars URLLoader URL


[Link]
[Link]
[Link]
UTF-8 UTF-16

[Link] application/x-www-form-urlencoded

[Link]()

URLLoader
URLRequest URLRequest HTTP
URL GET POST MIME
XML
XML ActionScript 3.0
request

var secondsUTC:Number = new Date().time;


var dataXML:XML =
<login>
<time>{secondsUTC}</time>
<username>Ernie</username>
<password>guru</password>
</login>;
var request:URLRequest = new URLRequest("[Link]
[Link]");
[Link] = "text/xml";
[Link] = [Link]();
[Link] = [Link];
var loader:URLLoader = new URLLoader();
try
{
[Link](request);
}
catch (error:ArgumentError)
{
trace("An ArgumentError has occurred.");
}
catch (error:SecurityError)
{
trace("A SecurityError has occurred.");
}

dataXML XML XML


URLRequest contentType text/xml URLRequest
data XML [Link]()
URLLoader [Link]()

561

URL

URLVariables

[Link]()

URLVariables

URLVariables [Link]()
and URL
& %26 URL

ActionScript 3.0
ActionScript

ActionScript

URLRequest URLLoader [Link]

var request:URLRequest = new URLRequest("[Link]");


var loader:URLLoader = new URLLoader();
[Link](request);

var loader:URLLoader = new URLLoader(new URLRequest("[Link]"));

Flash Player HTTP GET


POST [Link]
[Link] POST
var request:URLRequest = new URLRequest("[Link]");
[Link] = [Link];

[Link]
monthNames=January,February,March,April,May,June,July,August,September,October,
November,December&dayNames=Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,
Saturday

monthNames dayNames
[Link]()

562

[Link]

URLLoader data

private function completeHandler(event:Event):void


{
var loader2:URLLoader = URLLoader([Link]);
trace([Link]);
}

URLVariables

private function completeHandler(event:Event):void


{
var loader2:URLLoader = URLLoader([Link]);
var variables:URLVariables = new URLVariables([Link]);
trace([Link]);
}

- URLVariables
-
[Link]()
var dayNameArray:Array = [Link](",");

int() uint() Number()

URLVariables
[Link] URLLoaderDataFormat
[Link]

[Link] [Link]

ByteArray

String
[Link] [Link] URLVariables
URL
[Link] [Link]

[Link]
[Link] URLVariables
package
{
import
import
import
import
import

[Link];
[Link].*;
[Link];
[Link];
[Link];

public class URLLoaderDataFormatExample extends Sprite

563

{
public function URLLoaderDataFormatExample()
{
var request:URLRequest = new URLRequest("[Link]
[Link]");
var variables:URLLoader = new URLLoader();
[Link] = [Link];
[Link]([Link], completeHandler);
try
{
[Link](request);
}
catch (error:Error)
{
trace("Unable to load URL: " + error);
}
}
private function completeHandler(event:Event):void
{
var loader:URLLoader = URLLoader([Link]);
trace([Link]);
}
}
}

[Link] [Link]

XML URLVariables
URLRequest URLLoader XML
[Link] XML
XML
package
{
import
import
import
import
import

[Link];
[Link].*;
[Link].*;
[Link];
[Link];

public class ExternalDocs extends Sprite


{
public function ExternalDocs()
{
var request:URLRequest = new URLRequest("[Link]
[Link]");
var loader:URLLoader = new URLLoader();
[Link]([Link], completeHandler);
try

564

{
[Link](request);
}
catch (error:ArgumentError)
{
trace("An ArgumentError has occurred.");
}
catch (error:SecurityError)
{
trace("A SecurityError has occurred.");
}
}
private function completeHandler(event:Event):void
{
var dataXML:XML = XML([Link]);
trace([Link]());
}
}
}

URLVariables

variables URLVariables name


URLRequest
URL URLRequest method HTTP POST
URLVariables URL URLRequest data
URLVariables URLLoader
[Link]()
var variables:URLVariables = new URLVariables("name=Franklin");
var request:URLRequest = new URLRequest();
[Link] = "[Link]
[Link] = [Link];
[Link] = variables;
var loader:URLLoader = new URLLoader();
[Link] = [Link];
[Link]([Link], completeHandler);
try
{
[Link](request);
}

565

catch (error:Error)
{
trace("Unable to load URL");
}
function completeHandler(event:Event):void
{
trace([Link]);
}

Adobe ColdFusion [Link]


<cfif NOT IsDefined("[Link]") OR Len(Trim([Link])) EQ 0>
<cfset [Link] = "Stranger" />
</cfif>
<cfoutput>welcomeMessage=#UrlEncodedFormat("Welcome, " & [Link])#
</cfoutput>

Flash Player
LocalConnection Flash Player HTML
SWF Flash Player
Web SWF

LocalConnection
LocalConnection SWF fscommand()
JavaScript SWF LocalConnection
SWF
SWF
SWF SWF
SWF
Flash Player
LocalConnection ActionScript SWF

ActionScript 3.0 LocalConnection ActionScript 1.0 2.0


LocalConnection

ActionScript 1.0 2.0 LocalConnection ActionScript 3.0


LocalConnection
Flash Player LocalConnection

566

LocalConnection LocalConnection

ActionScript 3.0
send() connectionName LocalConnection
allowDomain() domain

LocalConnection SWF Adobe

LocalConnection

LocalConnection

[Link]

LocalConnection

LocalConnection
LocalConnection
package
{
import [Link];
public class CustomLocalConnection extends LocalConnection
{
public function CustomLocalConnection(connectionName:String)
{
try
{
connect(connectionName);
}
catch (error:ArgumentError)
{
// /
}
}
public function onMethod(timeString:String):void
{
trace("onMethod called at: " + timeString);
}
}
}

DynamicLocalConnection
var serverLC:CustomLocalConnection;
serverLC = new CustomLocalConnection("serverName");

Flash Player

567

[Link]
client
var lc:LocalConnection = new LocalConnection();
[Link] = new CustomClient();
[Link] client
CustomClient client LocalConnection
client

CustomClient
package
{
public class CustomClient extends Object
{
public function onMethod(timeString:String):void
{
trace("onMethod called at: " + timeString);
}
}
}

ActionScript
LocalConnection
import [Link];
dynamic class DynamicLocalConnection extends LocalConnection {}

var connection:DynamicLocalConnection = new DynamicLocalConnection();


[Link] = [Link];
//
public function onMethod(timeString:String):void
{
trace("onMethod called at: " + timeString);
}

568

Flash Player
LocalConnection Flash Player
Flash Player Flash Player Flash Player

Flash Player

package
{
import [Link];
import [Link];
public class ServerLC extends Sprite
{
public function ServerLC()
{
var lc:LocalConnection = new LocalConnection();
[Link] = new CustomClient1();
try
{
[Link]("conn1");
}
catch (error:Error)
{
trace("error:: already connected");
}
}
}
}

lc LocalConnection client
CustomClient1 Flash Player Flash
Player CustomClient1
Flash Player SWF
client CustomClient1
package
{
import [Link].*;
import [Link];
import [Link];
public class CustomClient1 extends Object
{
public function doMessage(value:String = ""):void
{
trace(value);
}
public function doQuit():void

Flash Player

569

{
trace("quitting in 5 seconds");
[Link]();
var quitTimer:Timer = new Timer(5000, 1);
[Link]([Link], closeHandler);
}
public function closeHandler(event:TimerEvent):void
{
fscommand("quit");
}
}
}

LocalConnection [Link]()
ArgumentError

conn1
try
{
[Link]("conn1");
}
catch (error:ArgumentError)
{
trace("Error! Server already exists\n");
}

ActionScript [Link]()
ActionScript 3.0

SWF SWF LocalConnection


LocalConnection
[Link]() LocalConnection

[Link]("conn1", "doQuit");

conn1 LocalConnection SWF


doQuit() SWF send()

[Link]("conn1", "doMessage", "Hello world");

570

SWF
LocalConnection allowDomain()
allowInsecureDomain() LocalConnection

ActionScript [Link]()
[Link]()
ActionScript 3.0 [Link]()
[Link]()
[Link]() [Link]()

[Link]() [Link]()
* localhost (*)
localhost SWF SWF

Flash Player 8 SWF Internet SWF


localhost SWF SWF
[Link]() SWF
securityError (SecurityErrorEvent.SECURITY_ERROR)
[Link]()
SWF (_)
connectionName myDomain:connectionName
[Link](connectionName)
SWF
connectionName LocalConnection SWF

connectionName Flash Player


myDomain:connectionName
LocalConnection
myDomain:connectionName LocalConnection
SWF Flash Player
anotherDomain:connectionName LocalConnection

connectionName _connectionNameFlash Player


LocalConnection
connectionName [Link]()
LocalConnection SWF
LocalConnection

Flash Player

571


ActionScript 3.0 XML
XML

XML XML
XML

XML XML

POP3 SMTP IMAP (NNTP)

Socket
ActionScript 3.0 Socket ActionScript
XMLSocket
Socket
Internet POP3 SMTP IMAP NNTP
Flash Player
Flash Player
big-endian little-endian Internet
big-endian big-endian little-endian
Intel x86
endian IDataInput IDataOutput
ByteArray Socket URLStream big-endian
Java
big-endian little-endian endian
Endian.BIG_ENDIAN Endian.LITTLE_ENDIAN

572

Socket IDataInput IDataOutput [Link]


Socket

XMLSocket
ActionScript XMLSocket

HTTP HTTP
XMLSocket

SWF
Java Python Perl
XMLSocket XMLSocket

TCP/IP XML

XML

XML (0)
XMLSocket XML

XMLSocket XMLSocket HTTP


(RTMP) HTTP Flash Remoting Flash
Media Server RTMP

XMLSocket

[Link]() 1024 TCP


XMLSocket
1024 1024 FTP (21)
Telnet (23) SMTP (25) HTTP (80) POP3 (110)
XMLSocket

[Link]() SWF
SWF [Link]()
SWF

XMLSocket
URLLoader XMLSocket

XMLSocket [Link]() [Link]()


XML [Link]() Web
[Link]() XML

573

[Link]() Flash Player

XMLSocket [Link]()
XMLSocket
Flash Player

TCP/IP

Java XML
Java XMLSocket

8080

import [Link].*;
import [Link].*;
class SimpleServer
{
private static SimpleServer server;
ServerSocket socket;
Socket incoming;
BufferedReader readerIn;
PrintStream printOut;
public static void main(String[] args)
{
int port = 8080;
try
{
port = [Link](args[0]);
}
catch (ArrayIndexOutOfBoundsException e)
{
//
}
server = new SimpleServer(port);
}
private SimpleServer(int port)
{
[Link](">> Starting SimpleServer");
try
{

574

socket = new ServerSocket(port);


incoming = [Link]();
readerIn = new BufferedReader(new
InputStreamReader([Link]()));
printOut = new PrintStream([Link]());
[Link]("Enter EXIT to exit.\r");
out("Enter EXIT to exit.\r");
boolean done = false;
while (!done)
{
String str = [Link]();
if (str == null)
{
done = true;
}
else
{
out("Echo: " + str + "\r");
if([Link]().equals("EXIT"))
{
done = true;
}
}
[Link]();
}
}
catch (Exception e)
{
[Link](e);
}
}
private void out(String str)
{
[Link](str);
[Link](str);
}
}

[Link] Java
[Link] Java
java SimpleServer XMLSocket
[Link] Web

Java classpath java -classpath .


SimpleServer

575

ActionScript XMLSocket XMLSocket


[Link]()
var xmlsock:XMLSocket = new XMLSocket();
[Link]("[Link]", 8080);

[Link]()
1024 securityError ([Link])
data ([Link])
[Link]([Link], onData);
private function onData(event:DataEvent):void
{
trace("[" + [Link] + "] " + [Link]);
}

XMLSocket [Link]() XML


Flash Player String XMLSocket
(0)
[Link](xmlFormattedData);
[Link]()

IOError

XML (\n)

Flash cookie
Web


[Link]() [Link]()
getLocal()
getRemote() Flash Media Server
getLocal() getRemote()
SharedObject
test

var so:SharedObject = [Link]("test");


trace("SharedObject is " + [Link] + " bytes");

576

test 0

var so:SharedObject = [Link]("test");


[Link] = new Date().time;
trace([Link]);
trace("SharedObject is " + [Link] + " bytes");

test now
[Link]
var so:SharedObject = [Link]("test");
if ([Link] == 0)
{
//
trace("created...");
[Link] = new Date().time;
}
trace([Link]);
trace("SharedObject is " + [Link] + " bytes");

size

[Link]()
var so:SharedObject = [Link]("test");
if ([Link] == 0)
{
//
trace("created...");
[Link] = new Date().time;
}
trace([Link]);
trace("SharedObject is " + [Link] + " bytes");
[Link]();

flush() Flash Player


([Link]/support/documentation/en/flashplayer/help/
settings_manager07.html)
var so:SharedObject = [Link]("test");
trace("Current SharedObject size is " + [Link] + " bytes.");
[Link]();

577

data
Flash Player SharedObject
var so:SharedObject = [Link]("test");
if ([Link] == 0)
{
//
trace("created...");
[Link] = new Date().time;
}
var ageMS:Number = new Date().time - [Link];
trace("SharedObject was created " + Number(ageMS / 1000 / 60).toPrecision(2)
+ " minutes ago");
trace("SharedObject is " + [Link] + " bytes");
[Link]();

test SharedObject
0 0 if true now
now
0

data for..in

var so:SharedObject = [Link]("test");


[Link] = "world";
[Link] = "bar";
[Link] = new Date().timezoneOffset;
for (var i:String in [Link])
{
trace(i + ":\t" + [Link][i]);
}

SharedObject
getLocal() getRemote() SharedObject secure
HTTPS SWF
true SWF HTTPS Flash Player

HTTPS SWF SWF [Link]()
secure true false SWF HTTPS
Flash Player

578

HTTPS SWF SWF


HTTPS true
null
HTTPS [Link]()
try
{
var so:SharedObject = [Link]("contactManager", null, true);
}
catch (error:Error)
{
trace("Unable to create SharedObject.");
}

FileReference
Windows

ActionScript FileReference

Mac OS creator null

FileReference new
import [Link];
var myFileReference:FileReference = new FileReference();

[Link]()

FileReference FileReference
FileReference FileReference name size
modificationDate

[Link]() [Link]()

[Link]()

[Link]

[Link]() [Link]()
[Link]() SWF

579

FileReference
FileReference
FileReference

FileReference

new FileReference
var myFileReference:FileReference = new FileReference();

[Link]() FileReference

SWF
SWF

browse() download()

HTTP POST

Content-Type multipart/form-data

Content-Disposition name Filedatafilename


[Link]() uploadDataFieldName
name

HTTP POST
POST /[Link] HTTP/1.1
Accept: text/*
Content-Type: multipart/form-data;
boundary=----------Ij5ae0ae0KM7GI3KM7ei4cH2ei4gL6
User-Agent: Shockwave Flash
Host: [Link]
Content-Length: 421
Connection: Keep-Alive
Cache-Control: no-cache
------------Ij5ae0ae0KM7GI3KM7ei4cH2ei4gL6
Content-Disposition: form-data; name="Filename"
[Link]
------------Ij5ae0ae0KM7GI3KM7ei4cH2ei4gL6
Content-Disposition: form-data; name="Filedata"; filename="[Link]"
Content-Type: application/octet-stream
Test File

580

------------Ij5ae0ae0KM7GI3KM7ei4cH2ei4gL6
Content-Disposition: form-data; name="Upload"
Submit Query
------------Ij5ae0ae0KM7GI3KM7ei4cH2ei4gL6
(actual file data,,,)

HTTP POST POST api_sig api_key auth_token


photo
POST /[Link] HTTP/1.1
Accept: text/*
Content-Type: multipart/form-data;
boundary=----------Ij5ae0ae0KM7GI3KM7ei4cH2ei4gL6
User-Agent: Shockwave Flash
Host: [Link]
Content-Length: 421
Connection: Keep-Alive
Cache-Control: no-cache
------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
Content-Disposition: form-data; name="Filename"
[Link]
------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
Content-Disposition: form-data; name="api_sig"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
Content-Disposition: form-data; name="api_key"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
Content-Disposition: form-data; name="auth_token"
XXXXXXXXXXXXXXXXXXXXXXX
------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
Content-Disposition: form-data; name="photo"; filename="[Link]"
Content-Type: application/octet-stream
(actual file data,,,)
------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7
Content-Disposition: form-data; name="Upload"
Submit Query
------------Ij5GI3GI3ei4GI3ei4KM7GI3KM7KM7--

581


browse()
[Link]()
[Link]() Flash Player
[Link] [Link]()

[Link]()
[Link]()

FileFilter browse()

var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif,


*.png)", "*.jpg; *.jpeg; *.gif; *.png");
var textTypes:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)",
"*.txt; *.rtf");
var allTypes:Array = new Array(imageTypes, textTypes);
var fileRef:FileReference = new FileReference();
[Link](allTypes);

[Link]
[Link]()
Web
var fileRef:FileReference = new FileReference();
[Link]([Link], selectHandler);
[Link]([Link], completeHandler);
try
{
var success:Boolean = [Link]();
}
catch (error:Error)
{
trace("Unable to browse for files.");
}
function selectHandler(event:Event):void
{
var request:URLRequest = new URLRequest("[Link]
[Link]")
try
{
[Link](request);
}
catch (error:Error)
{
trace("Unable to upload file.");

582

}
}
function completeHandler(event:Event):void
{
trace("uploaded");
}

[Link] [Link] [Link]()


POST GET

[Link]()

[Link]

[Link]

[Link]

SecurityErrorEvent.SECURITY_ERROR

HTTPStatusEvent.HTTP_STATUS

IOErrorEvent.IO_ERROR

HTTP

Flash Player /

SWF
Flash Player
url [Link]() HTTP HTTPS

Flash Player Microsoft


ActiveX SWF
ActiveX
/

ColdFusion

Flash Player

<cffile action="upload" filefield="Filedata" destination="#ExpandPath('./


')#" nameconflict="OVERWRITE" />

ColdFusion Flash Player ColdFusion

583

PHP
10 200 KB JPEG GIF PNG

<?php
$MAXIMUM_FILESIZE = 1024 * 200; // 200KB
$MAXIMUM_FILE_COUNT = 10; // keep maximum 10 files on server
echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE)
{
move_uploaded_file($_FILES['Filedata']['tmp_name'], "./temporary/
".$_FILES['Filedata']['name']);
$type = exif_imagetype("./temporary/".$_FILES['Filedata']['name']);
if ($type == 1 || $type == 2 || $type == 3)
{
rename("./temporary/".$_FILES['Filedata']['name'], "./images/
".$_FILES['Filedata']['name']);
}
else
{
unlink("./temporary/".$_FILES['Filedata']['name']);
}
}
$directory = opendir('./images/');
$files = array();
while ($file = readdir($directory))
{
array_push($files, array('./images/'.$file, filectime('./images/
'.$file)));
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT)
{
$files_to_delete = array_splice($files, 0, count($files) $MAXIMUM_FILE_COUNT);
for ($i = 0; $i < count($files_to_delete); $i++)
{
unlink($files_to_delete[$i][0]);
}
}
print_r($files);
closedir($directory);
function sorter($a, $b)
{
if ($a[1] == $b[1])
{
return 0;
}
else

584

{
return ($a[1] < $b[1]) ? -1 : 1;
}
}
?>

POST GET POST

var fileRef:FileReference = new FileReference();


[Link]([Link], selectHandler);
[Link]([Link], completeHandler);
[Link]();
function selectHandler(event:Event):void
{
var params:URLVariables = new URLVariables();
[Link] = new Date();
[Link] = "94103-1394-2345";
var request:URLRequest = new URLRequest("[Link]
FileReferenceUpload/[Link]");
[Link] = [Link];
[Link] = params;
[Link](request, "Custom1");
}
function completeHandler(event:Event):void
{
trace("uploaded");
}

URLVariables
ActionScript
ActionScript 3.0 URLRequest
POST GET
GET POST [Link]
[Link] [Link]
ActionScript 3.0 upload() Filedata
Custom1 Filedata
Flash Player true
upload()

Windows Flash Player

585


[Link]()
request defaultFileName URLRequest
URL
defaultFileName URL
SWF

[Link]

var request:URLRequest = new URLRequest("[Link]");


var fileRef:FileReference = new FileReference();
[Link](request);

[Link] [Link] defaultFileName

var request:URLRequest = new URLRequest("[Link]");


var fileToDownload:FileReference = new FileReference();
[Link](request, "[Link]");

defaultFileName
URL
defaultFileName
download()
URL ActionScript 3.0 ColdFusion
package
{
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];

public class DownloadFileExample extends Sprite


{
private var fileToDownload:FileReference;
public function DownloadFileExample()
{
var request:URLRequest = new URLRequest();
[Link] = "[Link]
[Link] = [Link];
[Link] = new URLVariables("id=2");
fileToDownload = new FileReference();
try
{
[Link](request, "[Link]");
}
catch (error:Error)

586

{
trace("Unable to download file.");
}
}
}
}

ColdFusion

[Link] URL

<cfparam name="[Link]" default="1" />


<cfswitch expression="#[Link]#">
<cfcase value="2">
<cfcontent type="text/plain" file="#ExpandPath('[Link]')#"
deletefile="No" />
</cfcase>
<cfdefaultcase>
<cfcontent type="text/plain" file="#ExpandPath('[Link]')#"
deletefile="No" />
</cfdefaultcase>
</cfswitch>

FileReferenceList
FileReferenceList
[Link]()
FileFilter imageFilter textFilter
[Link]()

var imageFilter:FileFilter = new FileFilter("Image Files (*.jpg, *.jpeg,


*.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
var textFilter:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)",
"*.txt; *.rtf");
var fileRefList:FileReferenceList = new FileReferenceList();
try
{
var success:Boolean = [Link](new Array(imageFilter,
textFilter));
}
catch (error:Error)
{
trace("Unable to browse for files.");
}

587

FileReferenceList
[Link]() FileReferenceList
[Link]()

var fileRefList:FileReferenceList = new FileReferenceList();


[Link]([Link], selectHandler);
[Link]();
function selectHandler(event:Event):void
{
var request:URLRequest = new URLRequest("[Link]
[Link]");
var file:FileReference;
var files:FileReferenceList = FileReferenceList([Link]);
var selectedFileArray:Array = [Link];
for (var i:uint = 0; i < [Link]; i++)
{
file = FileReference(selectedFileArray[i]);
[Link]([Link], completeHandler);
try
{
[Link](request);
}
catch (error:Error)
{
trace("Unable to upload files.");
}
}
}
function completeHandler(event:Event):void
{
trace("uploaded");
}

[Link] FileReference Flash


Player completeHandler()

588

Telnet
Telnet Socket

Socket telnet

ByteArray

[Link]/go/learn_programmingAS3samples_flash_cn Samples/Telnet
Telnet

[Link]

MXML

com/example/programmingas3/Telnet/
[Link]

Telnet

Telnet
[Link] (UI)
UI login() sendCommand()

ActionScript
import [Link];
private var telnetClient:Telnet;
private function connect():void
{
telnetClient = new Telnet([Link], int([Link]), output);
[Link] = "Connecting to " + [Link] + ":" +
[Link];
[Link] = true;
}
private function sendCommand():void
{
var ba:ByteArray = new ByteArray();
[Link]([Link] + "\n", "UTF-8");
[Link](ba);
[Link] = "";
}

Telnet

589

[Link] Telnet
Telnet telnetClient connect()
connect() telnetClient
telnet telnet TextArea
connect() Panel title
Panel
sendCommand() ByteArray

Telnet
Telnet Telnet /
Telnet
private
private
private
private
private

var
var
var
var
var

serverURL:String;
portNumber:int;
socket:Socket;
ta:TextArea;
state:int = 0;

serverURL
portNumber Telnet Telnet
23
socket

Socket serverURL portNumber

ta TextArea

Telnet

state Telnet
Telnet connect()

Telnet serverport outputserver port Telnet


output TextArea

public function Telnet(server:String, port:int, output:TextArea)


{
serverURL = server;
portNumber = port;
ta = output;
socket = new Socket();
[Link]([Link], connectHandler);
[Link]([Link], closeHandler);
[Link]([Link], errorHandler);
[Link](IOErrorEvent.IO_ERROR, ioErrorHandler);
[Link](ProgressEvent.SOCKET_DATA, dataHandler);

590

[Link]("[Link] + serverURL + "/[Link]");


try
{
msg("Trying to connect to " + serverURL + ":" + portNumber + "\n");
[Link](serverURL, portNumber);
}
catch (error:Error)
{
msg([Link] + "\n");
[Link]();
}
}

Socket writeBoolean()
writeByte()writeBytes() writeDouble() flush()
Telnet writeBytes()
writeBytesToSocket()
public function writeBytesToSocket(ba:ByteArray):void
{
[Link](ba);
[Link]();
}

sendCommand()

msg()
TextArea setScroll() TextArea
msg()
private function msg(value:String):void
{
[Link] += value;
setScroll();
}

TextArea

Telnet

591

TextArea
setScroll() ActionScript TextArea
setScroll()
public function setScroll():void
{
[Link] = [Link];
}

verticalScrollPosition
maxVerticalScrollPosition

FileIO Flash Player

[Link]/go/learn_programmingAS3samples_flash_cn Samples/FileIO
FileIO

[Link]

Flash Flex FLA


MXML

[Link]
com/example/programmingas3/fileio/
[Link]

com/example/programmingas3/fileio/
[Link]

592

FileIO
FileIO Flash Player
FileUpload FileDownload
[Link]
contentComplete init() ProgressBar
Button

[Link] Flash FLA


Flex
<example:FileUpload id="fileUpload"
creationComplete="[Link](uploadProgress, cancelUpload);" />
<example:FileDownload id="fileDownload"
creationComplete="[Link](downloadProgress, cancelDownload);" />


startUpload [Link]()
[Link]()
<mx:Panel title="Upload File" paddingTop="10" paddingBottom="10"
paddingLeft="10" paddingRight="10">
<mx:ProgressBar id="uploadProgress" label="" mode="manual" />
<mx:ControlBar horizontalAlign="right">
<mx:Button id="startUpload" label="Upload..."
click="[Link]();" />
<mx:Button id="cancelUpload" label="Cancel"
click="[Link]();" enabled="false" />
</mx:ControlBar>
</mx:Panel>

ProgressBar Button
(startUpload)
cancelUpload


<mx:Panel title="Download File" paddingTop="10" paddingBottom="10"
paddingLeft="10" paddingRight="10">
<mx:ProgressBar id="downloadProgress" label="" mode="manual" />
<mx:ControlBar horizontalAlign="right">
<mx:Button id="startDownload" label="Download..."
click="[Link]();" />
<mx:Button id="cancelDownload" label="Cancel"
click="[Link]();" enabled="false" />
</mx:ControlBar>
</mx:Panel>

593

(startDownload)
[Link]() FileDownload.DOWNLOAD_URL

cancelDownload

[Link]
[Link]
Flash Player FileDownload DOWNLOAD_URL
FileDownload [Link] 4

/**
* URL
*/
private const DOWNLOAD_URL:String = "[Link]
file_to_download.zip";
/**
* FileReference
*/
private var fr:FileReference;
/**
* ProgressBar
*/
private var pb:ProgressBar;
/**
*
*
*/
private var btn:Button;

DOWNLOAD_URL

fr FileReference [Link]()

pb btn ProgressBar
[Link]()

594

Button

FileDownload
FileDownload init() FileDownload
pb btn ProgressBar Button
init()
/**
* OPEN
* PROGRESS COMPLETE
*/
public function init(pb:ProgressBar, btn:Button):void
{
//
//
[Link] = pb;
[Link] = btn;
fr = new FileReference();
[Link]([Link], openHandler);
[Link]([Link], progressHandler);
[Link]([Link], completeHandler);
}

Download Button startDownload()


startDownload()
/**
* DOWNLOAD_URL
*/
public function startDownload():void
{
var request:URLRequest = new URLRequest();
[Link] = DOWNLOAD_URL;
[Link](request);
}

startDownload() URLRequest URL


DOWNLOAD_URL [Link]()
URLRequest
open
([Link]) openHandler()

595

openHandler() ProgressBar label


openHandler()
/**
* OPEN
*
*
*/
private function openHandler(event:Event):void
{
[Link] = "DOWNLOADING %3%%";
[Link] = true;
}

progress
([Link]) progress progressHandler()
ProgressBar progressHandler()
/**
*
*/
private function progressHandler(event:ProgressEvent):void
{
[Link]([Link], [Link]);
}

bytesLoaded bytesTotal ProgressBar


complete ([Link]) completeHandler()
completeHandler()

/**
*
*
*
*/
private function completeHandler(event:Event):void
{
[Link] = "DOWNLOAD COMPLETE";
[Link] = false;
}

596

/**
*
*/
public function cancelDownload():void
{
[Link]();
[Link] = "DOWNLOAD CANCELLED";
[Link] = false;
}

label

FileUpload

private const UPLOAD_URL:String = "[Link]


your_upload_script.cfm";
private var fr:FileReference;
private var pb:ProgressBar;
private var btn:Button;

FileDownload.DOWNLOAD_URL UPLOAD_URL
URL FileDownload

FileUpload
FileUpload init() pb
btn ProgressBar Button init()
FileUpload FileReference
FileReference init()
public function init(pb:ProgressBar, btn:Button):void
{
[Link] = pb;
[Link] = btn;
fr = new FileReference();
[Link]([Link], selectHandler);
[Link]([Link], openHandler);

597

[Link]([Link], progressHandler);
[Link]([Link], completeHandler);
}


[Link]() FileReference browse()

startUpload()
public function startUpload():void
{
[Link]();
}

select ([Link])
selectHandler() selectHandler() URLRequest
[Link] UPLOAD_URL
FileReference selectHandler()

private function selectHandler(event:Event):void


{
var request:URLRequest = new URLRequest();
[Link] = UPLOAD_URL;
[Link](request);
}

FileUpload FileDownload

progress ([Link])

598

23

23

(IME) SWF

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
ApplicationDomain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
IME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611

ActionScript
[Link]

SWF

Flash Player
mp3

IME

Flash Player HTML

[Link] IMEConversionMode SecurityPanel


IME Security
599


ActionScript

DPI

mp3

Flash Player

SWF

IME

IME

IME

IME

IME

(Operating system)
Microsoft Windows Mac OS X Linux

(Clipboard)

(Application domain) SWF


SWF

IME input method editor


600

trace()

1.

Flash

2.
3.
4. >

trace

1.

Flash

ActionScript Flash
SystemTest
[Link] ActionScript

2.

3.

ActionScript

4.
5.
6.

Flash
ActionScript
>


53

System
System Adobe Flash
Player System imeComposition
Flash Player Unicode

[Link] Flash Player

System

601

[Link]

(IME)

addEventListener() imeComposition

([Link].IME_COMPOSITION)
System useCodePage useCodePage true Flash
Player
false Flash Player Unicode
[Link] true

Windows

SWF
Unicode [Link] false
Flash Player Unicode

System setClipboard() Flash Player


[Link]()

private function securityErrorHandler(event:SecurityErrorEvent):void


{
var errorString:String = "[" + [Link] + "] " + [Link];
trace(errorString);
[Link](errorString);
}

Capabilities
Capabilities SWF Capabilities

Flash Player
Capabilities
[Link] [Link]

mp3 Capabilities.hasMP3 mp3

602

Flash Player
var versionString:String = [Link];
var pattern:RegExp = /^(\w*) (\d*),(\d*),(\d*),(\d*)$/;
var result:Object = [Link](versionString);
if (result != null)
{
trace("input: " + [Link]);
trace("platform: " + result[1]);
trace("majorVersion: " + result[2]);
trace("minorVersion: " + result[3]);
trace("buildNumber: " + result[4]);
trace("internalBuildNumber: " + result[5]);
}
else
{
trace("Unable to match RegExp.");
}

ActionScript
var url:String = "log_visitor.cfm";
var request:URLRequest = new URLRequest(url);
[Link] = [Link];
[Link] = new URLVariables([Link]);
var loader:URLLoader = new URLLoader(request);

ApplicationDomain
ApplicationDomain ActionScript 3.0 SWF

Loader API ActionScript 3.0 SWF


ActionScript 1.0 ActionScript 2.0 SWF
ActionScript 3.0
SWF LoaderContext applicationDomain
[Link] Loader
SWF
SWF
SWF
package
{
import [Link];
import [Link];
import [Link].*;

ApplicationDomain

603

import [Link];
import [Link];
import [Link];
public class ApplicationDomainExample extends Sprite
{
private var ldr:Loader;
public function ApplicationDomainExample()
{
ldr = new Loader();
var req:URLRequest = new URLRequest("[Link]");
var ldrContext:LoaderContext = new LoaderContext(false,
[Link]);
[Link]([Link],
completeHandler);
[Link](req, ldrContext);
}
private function completeHandler(event:Event):void
{
[Link]("Greeter");
var myGreeter:Greeter = Greeter([Link]);
var message:String = [Link]("Tommy");
trace(message); // Hello, Tommy
}
}
}

SWF
Flash Player

604

([Link]) SWF

SWF
[Link]

1
[Link]

[Link]
[Link]

3
[Link]

2
[Link]

[Link]

[Link] SWF Loader


Application domain 1 A B C
SWF

SWF Application domain 2


[Link] Application domain 2
[Link]
A

[Link] = "[Link]";
[Link] = new ApplicationDomain();

ApplicationDomain

605

B [Link]

(Application domain 1)
SWF (RSL)
RSL

[Link] = "[Link]";
[Link] = [Link];

C [Link]

Internet (RIA)

SWF

singleton

[Link] = "[Link]";
[Link] = new
ApplicationDomain([Link]);

IME
IME Flash

Player IME

ActionScript

IME ([Link])

IME ([Link])

IME ([Link])

IME
IME
IME ASCII
IME
Web

[Link]
[Link]
[Link]

606

IME IME [Link]


IME IME ActionScript
IME IME

IME
IME IME
IME
if ([Link])
{
if ([Link])
{
trace("IME is installed and enabled.");
}
else
{
trace("IME is installed but not [Link] enable your IME and try
again.");
}
}
else
{
trace("IME is not [Link] install an IME and try again.");
}

[Link] IME
true [Link] IME

IME
IME
IME IME IME

if ([Link])
{
switch ([Link])
{
case IMEConversionMode.ALPHANUMERIC_FULL:
[Link] = "Current conversion mode is alphanumeric (full-width).";
break;
case IMEConversionMode.ALPHANUMERIC_HALF:
[Link] = "Current conversion mode is alphanumeric (half-width).";
break;
case [Link]:
[Link] = "Current conversion mode is Chinese.";
break;
case IMEConversionMode.JAPANESE_HIRAGANA:
[Link] = "Current conversion mode is Japananese Hiragana.";
break;
case IMEConversionMode.JAPANESE_KATAKANA_FULL:

IME

607

[Link] = "Current conversion mode is Japanese Katakana (fullwidth).";


break;
case IMEConversionMode.JAPANESE_KATAKANA_HALF:
[Link] = "Current conversion mode is Japanese Katakana (halfwidth).";
break;
case [Link]:
[Link] = "Current conversion mode is Korean.";
break;
default:
[Link] = "Current conversion mode is " + [Link] + ".";
break;
}
}
else
{
[Link] = "Please install an IME and try again.";
}

IME [Link]
IMEConversionMode IME

IME

IME try..catch
IME

conversionMode

[Link] try..catch
var statusText:TextField = new TextField;
[Link] = [Link];
addChild(statusText);
if ([Link])
{
try
{
[Link] = true;
[Link] = [Link];
[Link] = "Conversion mode is " + [Link] + ".";
}
catch (error:Error)
{
[Link] = "Unable to set conversion mode.\n" + [Link];
}
}

IME IME
IMEFlash Player try..catch try..catch

608

IME
IME
IME
FocusEvent.FOCUS_IN FocusEvent.FOCUS_OUT
IME
var phoneTxt:TextField = new TextField();
var nameTxt:TextField = new TextField();
[Link] = [Link];
[Link](FocusEvent.FOCUS_IN, focusInHandler);
[Link](FocusEvent.FOCUS_OUT, focusOutHandler);
[Link] = "0-9";
[Link] = 100;
[Link] = 18;
[Link] = true;
[Link] = true;
addChild(phoneTxt);
[Link] = [Link];
nameField.x = 120;
[Link] = 100;
[Link] = 18;
[Link] = true;
[Link] = true;
addChild(nameField);
function focusInHandler(event:FocusEvent):void
{
if ([Link])
{
[Link] = false;
}
}
function focusOutHandler(event:FocusEvent):void
{
if ([Link])
{
[Link] = true;
}
}

phoneTxt nameTxt phoneTxt


phoneTxt FocusEvent.FOCUS_IN
IME phoneTxt FocusEvent.FOCUS_OUT
IME

IME

609

IME
IME IME
IMEEvent.IME_COMPOSITION
IMEEvent.IME_COMPOSITION System ime
([Link](...))
var inputTxt:TextField;
var outputTxt:TextField;
inputTxt = new TextField();
[Link] = [Link];
[Link] = 200;
[Link] = 18;
[Link] = true;
[Link] = true;
addChild(inputTxt);
outputTxt = new TextField();
[Link] = [Link];
outputTxt.y = 20;
addChild(outputTxt);
if ([Link])
{
[Link] = true;
try
{
[Link] = IMEConversionMode.JAPANESE_HIRAGANA;
}
catch (error:Error)
{
[Link] = "Unable to change IME.";
}
[Link](IMEEvent.IME_COMPOSITION,
imeCompositionHandler);
}
else
{
[Link] = "Please install IME and try again.";
}
function imeCompositionHandler(event:IMEEvent):void
{
[Link] = "you typed: " + [Link];
}

inputTxt
outputTxt
inputTxt

610


CapabilitiesExplorer [Link] Flash
Player

Capabilities Flash Player

ExternalInterface

[Link]/go/learn_programmingAS3samples_flash_cn
Samples/CapabilitiesExplorer CapabilitiesExplorer

[Link]

Flash Flex FLA


MXML

[Link]

com/example/programmingas3/capabilities/
[Link]

ExternalInterface
[Link]

API JavaScript
HTML

CapabilitiesExplorer
[Link] CapabilitiesExplorer
Flash Player DataGrid HTML
API
creationComplete initApp() initApp()
[Link]
getCapabilities() initApp()
private function initApp():void
{
var dp:Array = [Link]();
[Link] = dp;
}
[Link]()

Flash Player
capabilitiesGrid DataGrid dataProvider

611

CapabilitiesGrabber
CapabilitiesGrabber getCapabilities() [Link]
(capDP) CapabilitiesGrabber
getBrowserObjects() getBrowserObjects() API
getCapabilities()
public static function getCapabilities():Array
{
var capDP:Array = new Array();
[Link]({name:"[Link]",
value:[Link]});
[Link]({name:"[Link]",
value:[Link]});
[Link]({name:"[Link]", value:[Link]});
...
[Link]({name:"[Link]", value:[Link]});
var navArr:Array = [Link]();
if ([Link] > 0)
{
capDP = [Link](navArr);
}
[Link]("name", [Link]);
return capDP;
}
getBrowserObjects()
(navArr) Flash Player
(capDP)
getBrowserObjects()
private static function getBrowserObjects():Array
{
var itemArr:Array = new Array();
var itemVars:URLVariables;
if ([Link])
{
try
{
var tempStr:String = [Link]("JS_getBrowserObjects");
itemVars = new URLVariables(tempStr);
for (var i:String in itemVars)
{
[Link]({name:i, value:itemVars[i]});
}
}
catch (error:SecurityError)
{
// ignore
}

612

}
return itemArr;
}

API Flash Player JavaScript


JS_getBrowserObjects() ActionScript
URL URLVariables
(itemVars) itemArr

JavaScript
CapabilitiesExplorer
JavaScript - [Link]
JavaScript JS_getBrowserObjects()
<script language="JavaScript">
function JS_getBrowserObjects()
{
//
var tempArr = new Array();
//
for (var name in navigator)
{
var value = navigator[name];
// Boolean
//
switch (typeof(value))
{
case "string":
case "boolean":
//
// JavaScript
// escape() URL
var tempStr = "navigator." + name + "=" + escape(value);
// URL /
[Link](tempStr);
break;
}
}
//
for (var name in screen)
{
var value = screen[name];
//

613

//
switch (typeof(value))
{
case "number":
var tempStr = "screen." + name + "=" + escape(value);
[Link](tempStr);
break;
}
}
// URL -
return [Link]("&");
}
</script>

-
for..in
String Boolean
String Boolean tempArr
for..in tempArr
[Link]() (&)
ActionScript URLVariables

614

24

24

Adobe Flash Player 9


Flash Player
Flash Player
[Link]
[Link]
Flash Player

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .623
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .625

615

ActionScript 3.0 PrintJob

ActionScript

PrintJob

(Spooler)

(Page orientation)

616

(Print job)

1.

Flash

2.

3.
4. >

SWF

PrintJob

Flash Player

new PrintJob()

[Link]()

[Link]() Sprite

addPage() sprite

[Link]()

packageimport class

package
{
import [Link];
import [Link];
public class BasicPrintExample extends Sprite
{
var myPrintJob:PrintJob = new PrintJob();
var mySprite:Sprite = new Sprite();
public function BasicPrintExample()
{
[Link]();
[Link](mySprite);
[Link]();

617

}
}
}

618

PrintJob
myPrintJob = null

PrintJob null

Flash Player
Flash Player Flash Player
Flash Player

Flash Player

addPage() send()
[Link]() true
if
if ([Link]())
{
// addPage() send()
}

[Link]() true Print Flash Player


Print addPage() send()
Flash Player [Link]()
[Link]()
addPage() try..catch
[params]
if ([Link]())
{
try
{
[Link]([params]);
}
catch (error:Error)

618

{
//
}
[Link]();
}

[Link]()
catch
Flash Player
[Link]()
Flash Player
Flash Player
Flash if..else

if ([Link]())
{
try
{
[Link]([params]);
}
catch (error:Error)
{
//
}
[Link]();
}
else
{
[Link] = "Print job canceled";
}

625

[Link]() true
pageHeight pageWidth
Flash Player

621

Flash Player

619

Alpha
PostScript
[Link]() PrintJobOptions
printAsBitmap true
var options:PrintJobOptions = new PrintJobOptions();
[Link] = true;
[Link](mySprite, null, options);

printArea printArea
null

ActionScript ActionScript 3.0 PrintJob



[Link]() [Link]()
[Link]()
ActionScript 3.0 15
15 15

[Link]() [Link]()

[Link]() [Link]()

[Link]() [Link]()

15 PrintJob [Link]()
false PrintJob [Link]() Flash Player

620


617
sprite
sprite

Flash Player

[Link]() sprite printArea


Rectangle

Rectangle addPage()

private var rect1:Rectangle = new Rectangle(0, 0, 400, 200);


[Link](sheet, rect1);

Rectangle
[Link](sheet, new Rectangle(0, 0, 100, 100));

addPage()
null
[Link](sheet, null, options);

[Link]

1/72
sprite 72 sprite

1/20

1 = 1/72 = 20
1 = 72 = 1440
1 = 567

printArea

sprite

621


Sprite [Link]()
346
Sprite printArea 50 x 50
2500 Sprite 2500
Sprite
625

Flash Player

ActionScript

if ([Link] == [Link])
{
[Link] = 90;
}

PrintJobOrientation
import [Link];

PrintJobOrientation

if
if ([Link] > [Link])
{
[Link] = .75;
}

margin_height = ([Link] - [Link]) / 2;


margin_width = ([Link] - [Link]) / 2;

622


sprite sheet1 sheet2
sprite [Link]()
package
{
import
import
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];

public class PrintMultiplePages extends MovieClip


{
private var sheet1:Sprite;
private var sheet2:Sprite;
public function PrintMultiplePages():void
{
init();
printPages();
}
private function init():void
{
sheet1 = new Sprite();
createSheet(sheet1, "Once upon a time...", {x:10, y:50, width:80,
height:130});
sheet2 = new Sprite();
createSheet(sheet2, "There was a great story to tell, and it ended
quickly.\n\nThe end.", null);
}
private function createSheet(sheet:Sprite, str:String,
imgValue:Object):void
{
[Link](0xEEEEEE);
[Link](1, 0x000000);
[Link](0, 0, 100, 200);
[Link]();
var txt:TextField = new TextField();
[Link] = 200;
[Link] = 100;
[Link] = true;
[Link] = str;

623

if (imgValue != null)
{
var img:Sprite = new Sprite();
[Link](0xFFFFFF);
[Link](imgValue.x, imgValue.y, [Link],
[Link]);
[Link]();
[Link](img);
}
[Link](txt);
}
private function printPages():void
{
var pj:PrintJob = new PrintJob();
var pagesToPrint:uint = 0;
if ([Link]())
{
if ([Link] == [Link])
{
throw new Error("Page is not set to an orientation of
portrait.");
}
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
[Link] = [Link];
try
{
[Link](sheet1);
pagesToPrint++;
}
catch (error:Error)
{
//
}
try
{
[Link](sheet2);
pagesToPrint++;
}
catch (error:Error)
{
//
}
if (pagesToPrint > 0)

624

{
[Link]();
}
}
}
}
}

scaleX
scaleY

txt

Flash Player

package
{
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];

public class PrintScaleExample extends Sprite


{
private var bg:Sprite;
private var txt:TextField;
public function PrintScaleExample():void
{
init();
draw();
printPage();
}
private function printPage():void
{
var pj:PrintJob = new PrintJob();
[Link] = 3;
[Link] = 2;
if ([Link]())
{
trace(">> [Link]: " + [Link]);

625

trace(">>
trace(">>
trace(">>
trace(">>

[Link]: " + [Link]);


[Link]: " + [Link]);
[Link]: " + [Link]);
[Link]: " + [Link]);

try
{
[Link](this, new Rectangle(0, 0, 100, 100));
}
catch (error:Error)
{
//
}
[Link]();
}
else
{
[Link]
}
// txt
[Link]
[Link]

= "Print job canceled";

= 1;
= 1;

}
private function init():void
{
bg = new Sprite();
[Link](0x00FF00);
[Link](0, 0, 100, 200);
[Link]();
txt = new TextField();
[Link] = true;
[Link] = "Hello World";
}
private function draw():void
{
addChild(bg);
addChild(txt);
txt.x = 50;
txt.y = 50;
}
}
}

626

25

25

API

ActionScript 3.0 API ActionScript Adobe Flash Player 9


API SWF
HTML JavaScript Flash
Player SWF
API ActionScript HTML
JavaScript ActionScript

SWF ActionScript SWF


Flash Player Flash Player
Flash Player

API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .628
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
ExternalInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .636
API ActiveX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .642

627

API
API
SWF SWF
SWF SWF
HTML SWF
SWF
HTML SWF

SWF ActionScript API


SWF ActionScript

API
API

ActionScript

ActionScript

ActionScript

628

ActiveX (ActiveX container) Web Flash


Player ActiveX SWF
(Container application)Flash Player SWF
Web Flash Player HTML
(Projector) SWF Flash Player
SWF Adobe Flash CS3 Professional Flash
Player CD-ROM SWF
SWF SWF
SWF Flash Player

API

(Proxy)

(Serialize)
Internet

API
ActionScript
SWF
ActionScript JavaScript
1. Flash
2. >
3. Flash HTML

4.

SWF HTML
Flash

5. HTML

HTML
JavaScript HTML HTML Flash
SWF HTML

6.
7. HTML Flash SWF HTML

HTML

JavaScript

8.

HTML Flash
9. 1
10. ActionScript

API

629

11. >

SWF
12. Web HTML ActionScript
HTML
ActionScript ActiveX
1. Flash
SWF
2. >
3. Flash
4. Flash

SWF
SWF Flash
SWF

5.

1
6. ActionScript
7. > SWF
8. ActionScript
API HTML
API C#
ActionScript API
API ActionScript 3.0
ExternalInterface

API
API ActionScript ActionScript Flash Player
Web
ActionScript 3.0 API ExternalInterface
Flash Player 8 Flash Player fscommand()
ExternalInterface fscommand() JavaScript ActionScript

fscommand() SWF
Flash Player [Link]

ExternalInterface ActionScript Flash Player


HTML JavaScript Flash Player
630

API

ExternalInterface

Internet Explorer for Windows 5.0

Flash Player ActiveX

NPRuntime

Firefox 1.0

Mozilla 1.7.5

Netscape 8.0

Safari 1.3
[Link]
false
ActionScript HTML
API

JavaScript fscommand()

JavaScript fscommand()

API fscommand()

Boolean Number String String

ActionScript

HTML Flash Player object id (-)


JavaScript + * / \ . Internet Explorer
ActionScript ExternalInterface
Flash Player HTML object embed HTML form
ActionScript ExternalInterface

ExternalInterface
ActionScript ActionScript
JavaScript ActionScript

ExternalInterface
ActionScript
ActionScript

ExternalInterface

631


[Link]

Flash Player
true false ExternalInterface

if ([Link])
{
// ExternalInterface
}

[Link] ExternalInterface
JavaScript

[Link] Flash Player


Internet Explorer object id NPRuntime
embed name ID SWF
SWF HTML JavaScript
Flash Player Web null

ActionScript
[Link]()

[Link]()

// addNumbers
//
// result
var param1:uint = 3;
var param2:uint = 7;
var result:uint = [Link]("addNumbers", param1, param2);

HTML JavaScript HTML


script JavaScript ActionScript
<script language="JavaScript">
// ActionScript
function addNumbers(num1, num2)
{
return (num1 + num2);
}
</script>

632

API

ActiveX Flash Player ActiveX


FlashCall Flash Player XML
request
ActionScript ActiveX SetReturnValue()
XML XML
634 API XML
Web ActiveX
null
[Link]() SecurityError
allowScriptAccess HTML
allowScriptAccess object embed

ActionScript
ActionScript ActionScript
ActionScript ExternalInterface

ActionScript
[Link]()
function callMe(name:String):String
{
return "busy signal";
}
[Link]("myFunction", callMe);
addCallback() String
ActionScript

ActionScript

ExternalInterface ActionScript
Web JavaScript
ActionScript Flash Player
object embed JavaScript

<script language="JavaScript">
// callResult gets the value "busy signal"
var callResult = [Link]("my name");
</script>
...
<object id="flashObject"...>

ExternalInterface

633

...
<embed name="flashObject".../>
</object>

SWF ActionScript
XML XML
ActiveX CallFunction()
XML 634 API XML
ActionScript
JavaScript ActiveX XML

API XML
ActionScript Shockwave Flash ActiveX
XML API XML

XML ActionScript ActionScript


ActionScript Flash Player XML
Flash Player XML XML
XML
<invoke name="functionName" returntype="xml">
<arguments>
... (individual argument values)
</arguments>
</invoke>

invoke name returntype


xml invoke arguments

634

API


ActionScript
XML

ActionScript C# /
/

null

null

<null/>

Boolean true

bool true

<true/>

Boolean false

bool false

<false/>

String

string

<string>string value</string>

Number int
uint

single
double int
uint

<number>27.5</number>

<number>-12</number>

Array

ArrayList
object[]

<array>
<property id="0">
<number>27.5</number>
</property>
<property id="1">
<string>Hello there!</
string>
</property>
...
</array>

property
id
0

Object

<object>
<property id="name">
<string>John Doe</string>
</property>
<property id="age">
<string>33</string>
</property>
...
</object>

property
id

<null/>

ActionScript
null

HashTable

<object></object>

ActionScript C# API
ActiveX C#

API ActiveX
XML
C# 646 ExternalInterfaceProxy

ExternalInterface

635

API
ActionScript Web JavaScript

Introvert IM API HTML SWF

API

ActionScript

JavaScript
ActionScript JavaScript

[Link]/go/learn_programmingAS3samples_flash_cn Introvert IM
Samples/IntrovertIM_HTML

[Link]

Flash Flex FLA


MXML

[Link]

com/example/programmingas3/introvertIM/ ActionScript
[Link]
com/example/programmingas3/introvertIM/
[Link]
IMManager
com/example/programmingas3/introvertIM/
[Link]

html-flash/[Link]

html-template/[Link]

636

API

Flash HTML (html-flash/


[Link]) Adobe Flex
HTML (html-template/
[Link])
JavaScript

ActionScript
API ActionScript Web
API ActionScript JavaScript
SWF HTML
JavaScript JavaScript SWF
SWF HTML SWF
IMManager Introvert IM
SWF
IMManager
public function IMManager(initialStatus:IMStatus)
{
_status = initialStatus;
// API
if ([Link])
{
try
{
// isContainerReady()
// Flash Player
// SWF
var containerReady:Boolean = isContainerReady();
if (containerReady)
{
// SWF
setupCallbacks();
}
else
{
// Timer
// 100
//
var readyTimer:Timer = new Timer(100);
[Link]([Link], timerHandler);
[Link]();
}
}
...
}
else
{
trace("External interface is not available for this container.");
}
}

API

637

[Link] API

try catch
isContainerReady()
private function isContainerReady():Boolean
{
var result:Boolean = [Link]("isReady");
return result;
}
isContainerReady() [Link]()

JavaScript

isReady()
<script language="JavaScript">
<!-// ------- Private vars ------var jsReady = false;
...
// ------- ActionScript ------// JavaScript
function isReady()
{
return jsReady;
}
...
// <body> onload
function pageInit()
{
// JavaScript
jsReady = true;
}
...
//-->
</script>
isReady() jsReady false
onload true

ActionScript
isReady() JavaScript [Link]("isReady") false
ActionScript isContainerReady() false JavaScript
isReady() true ActionScript isContainerReady() true

638

API

IMManager
isContainerReady() true setupCallbacks()
JavaScript isContainerReady() false
Timer 100 timerHandler()

private function timerHandler(event:TimerEvent):void


{
//
var isReady:Boolean = isContainerReady();
if (isReady)
{
//
//
Timer([Link]).stop();
// ActionScript
//
setupCallbacks();
}
}

timerHandler() isContainerReady()
true Timer setupCallbacks()

JavaScript ActionScript
setupCallbacks()
ActionScript JavaScript
private function setupCallbacks():void
{
// SWF
[Link]("newMessage", newMessage);
[Link]("getStatus", getStatus);
// SWF
[Link]("setSWFIsReady");
}
setCallBacks() [Link]()

JavaScript
ActionScript JavaScript newMessage
getStatus
[Link]() JavaScript
setSWFIsReady() ActionScript

API

639

ActionScript
Introvert IM JavaScript
setupCallbacks() JavaScript setSWFIsReady()

[Link]("setSWFIsReady");

isContainerReady() ActionScript isReady()

var result:Boolean = [Link]("isReady");

API JavaScript IMManager sendMessage()



public function sendMessage(message:String):void
{
[Link]("newMessage", message);
}

[Link]() JavaScript
[Link]()
JavaScript newMessage()

JavaScript ActionScript
Introvert IM Flash Player IM
JavaScript HTML JavaScript SWF
SWF
IMManager getStatus() SWF IM
updateStatus()
<script language="JavaScript">
...
function updateStatus()
{
if (swfReady)
{
var currentStatus = getSWF("IntrovertIMApp").getStatus();
[Link]["imForm"].[Link] = currentStatus;
}
}
...
</script>

640

API

swfReady SWF
ExternalInterface SWF
(var currentStatus = ...) IMManager getStatus()

getSWF() JavaScript SWF JavaScript


HTML SWF getSWF()
object id SWF
embed name

SWF getStatus() SWF


getStatus
[Link]() ActionScript

getStatus() ActionScript currentStatus


status value

JavaScript ActionScript
sendMessage() HTML
sendMessage()

<script language="JavaScript">
...
function sendMessage(message)
{
if (swfReady)
{
...
getSWF("IntrovertIMApp").newMessage(message);
}
}
...
</script>
newMessage() ActionScript JavaScript message
JavaScript newMessage() ActionScript

JavaScript

getSWF() JavaScript
<script language="JavaScript">
...
function getSWF(movieName)
{
if ([Link]("Microsoft") != -1)
{

API

641

return window[movieName];
}
else
{
return document[movieName];
}
}
...
</script>

HTML SWF

API ActiveX
API ActionScript ActiveX
Introvert IM ActionScript
SWF API ActionScript

Microsoft Visual Studio .NET C#


ActiveX API

Flash Player ActiveX

ActionScript
ActiveX
proxy XML Flash Player
ActiveX
ActionScript

[Link]/go/learn_programmingAS3samples_flash_cn Introvert IM C#
Samples/IntrovertIM_CSharp

[Link]

C# Windows Forms

bin/Debug/[Link]

SWF

ExternalInterfaceProxy/
[Link]

ActiveX External Interface


ActionScript

ExternalInterfaceProxy/
[Link]

Flash Player XML .NET

ExternalInterfaceProxy/
[Link]

C#
ExternalInterfaceProxy
ActionScript

642

API

ExternalInterfaceProxy/
[Link]

ActionScript
ActiveX

bin/Debug/[Link]

SWF

obj/[Link],
obj/[Link]

Visual Studio .NET


Flash Player (Adobe
Shockwave Flash) ActiveX

Introvert IM C#
SWF
Windows Forms Shockwave Flash ActiveX
ActionScript IM SWF
Windows Forms IM (MessageText)
(Transcript) SWF IM
(Status)

Shockwave Flash ActiveX


Shockwave Flash ActiveX
Microsoft Visual Studio

Windows Forms

Visual Studio

1.

Visual Studio 2003 Windows Forms Visual Studio 2005


Visual Studio 2003 / Visual
Studio 2005 ...
(2003)/ (2005)
COM COM
Flash Player ActiveX
Shockwave Flash Object
Flash Player ActiveX

2.

3.

4.

API ActiveX

643

ActionScript ActiveX
API ActiveX Web
ActionScript Web

API ActiveX
Flash Player XML
XML ActiveX

Introvert IM C#
ActionScript ActionScript
ExternalInterfaceProxy .NET
API
([Link]) ExternalInterfaceProxy

public class AppForm : [Link]


{
...
private ExternalInterfaceProxy proxy;
...
public AppForm()
{
...
//
// ActionScript
proxy = new ExternalInterfaceProxy(IntrovertIMApp);
[Link] += new
ExternalInterfaceCallEventHandler(proxy_ExternalInterfaceCall);
...
}
...

proxy ExternalInterfaceProxy
(IntrovertIMApp) Shockwave Flash ActiveX
proxy_ExternalInterfaceCall() ExternalInterfaceCall
Flash Player ExternalInterfaceProxy C#
ActionScript

644

API

ActionScript ExternalInterfaceProxy (proxy)


XML ExternalInterfaceCall
AppForm proxy_ExternalInterfaceCall()
/// <summary>
/// SWF ActionScript ExternalInterface
///
/// </summary>
private object proxy_ExternalInterfaceCall(object sender,
ExternalInterfaceCallEventArgs e)
{
switch ([Link])
{
case "isReady":
return isReady();
case "setSWFIsReady":
setSWFIsReady();
return null;
case "newMessage":
newMessage((string)[Link][0]);
return null;
case "statusChange":
statusChange();
return null;
default:
return null;
}
}
...

ExternalInterfaceCallEventArgs e
FunctionCall ExternalInterfaceCall

ExternalInterfaceCall FunctionName
ActionScript [Link]() ActionScript
ExternalInterfaceCall Arguments
switch FunctionName
([Link]) AppForm
switch

ActionScript isReady() null


newMessage() [Link][0]
Arguments ActionScript

API ActiveX

645

ExternalInterfaceProxy C# ActionScript ActionScript


ActionScript ExternalInterfaceProxy
Call()
/// <summary>
///
/// MessageText
/// </summary>
/// <param name="message"> </param>
private void sendMessage(string message)
{
if (swfReady)
{
...
// ActionScript newMessage
[Link]("newMessage", message);
}
}
...
/// <summary>
/// ActionScript
///
/// </summary>
private void updateStatus()
{
[Link] = (string)[Link]("getStatus");
}
...
}

ExternalInterfaceProxy Call() ActionScript


[Link]()
ActionScript ActionScript
Call()

ExternalInterfaceProxy
ActiveX

Shockwave Flash ActiveX CallFunction() API


ActiveX ActionScript ExternalInterfaceProxy Call()

// _flashControl SWF ActionScript


// _flashControl Shockwave Flash ActiveX
string response = _flashControl.CallFunction(request);

646

API

_flashControl Shockwave Flash ActiveX


CallFunction() ActionScript
request XML ActionScript
ActionScript XML
CallFunction() XML response

ActionScript ActionScript
Shockwave Flash ActiveX FlashCall SWF
ExternalInterfaceProxy
ExternalInterfaceProxy _flashControl_FlashCall()

private AxShockwaveFlash _flashControl;


public ExternalInterfaceProxy(AxShockwaveFlash flashControl)
{
_flashControl = flashControl;
_flashControl.FlashCall += new
_IShockwaveFlashEvents_FlashCallEventHandler(_flashControl_FlashCall);
}
...
private void _flashControl_FlashCall(object sender,
_IShockwaveFlashEvents_FlashCallEvent e)
{
// request [Link]
//
...
// ActionScript
// XML
_flashControl.SetReturnValue(encodedResponse);
}

(e) request ([Link]) XML

ExternalInterfaceProxy XML ExternalInterfaceCall


ActiveX SetReturnValue()
ActionScript API XML

API ActiveX

647

ActionScript Shockwave Flash ActiveX XML


Introvert IM C# ExternalInterfaceProxy
ActionScript
Flash Player XML ExternalInterfaceProxy
ExternalInterfaceSerializer XML .NET
ExternalInterfaceSerializer

EncodeInvoke() C# ArrayList XML

EncodeResult() XML

DecodeInvoke() ActionScript FlashCall


request DecodeInvoke()

ExternalInterfaceCall

DecodeResult() ActionScript XML


C# API XML XML C# Flash
Player XML 634 API XML

648

API

26

Flash Player

26

Adobe Adobe Flash


Player 9
Flash Flash Player
SWF ActionScript 3.0 Flash
Player 9

API Flash Player Flash


Player 9 [Link]/go/fp9_0_security_cn

Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .652
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .662
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .664
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .665
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .668
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
SWF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
LocalConnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680

649

Flash Player
Flash Player SWF
Internet [Link] SWF
660

SWF SWF
SWF ActionScript 3.0
SWF
ActionScript SWF ActionScript 3.0
SWF ActionScript SWF
LocalConnection
668

SWF

Flash Player

[Link]

[Link]

[Link]

[Link]

[Link]

[Link] IP
[Link] Flash Player
SWF SWF

[Link]() 659

656 Web

SWF ActionScript 3.0 SWF


SWF [Link]()
668

650

Flash Player

Flash Player

Flash Player
SWF ActionScript
Loader Sound NetStream


XML
Bitmap [Link]() Sound.id3
[Link]()
URLStream URLLoader Socket XMLSocket

Flash Player

SWF MP3
SWF

SWF

661

(RTMP)
668 RTMP

SWF
SWF
671
XML URLLoader

674 URLLoader URLStream

Flash Player

651


Flash Player SWF Internet URL

Flash Player

Flash
Player

[Link]
Flash Player

652

Flash Player

[Link]
Mac OS X [Link] /Library/Application Support/Macromedia
Microsoft Windows Macromedia Flash Player
Windows XP C:\windows\system32\macromed\flash\[Link]

Flash Player
[Link]

SWF

SWF
URL SWF

Flash Player Flash Player Flash


Player URL Flash Player URL
Flash Player
SWF

SWF [Link]
[Link] [Link]

ActionScript
[Link]
[Link]
[Link] Adobe
[Link]

Flash Player
SWF SWF
SWF
Flash Player
[Link]

Windowssystem\Macromed\Flash\FlashPlayerTrust
C:\windows\system32\Macromed\Flash\FlashPlayerTrust

Macapp support/Macromedia/FlashPlayerTrust
/Library/Application Support/Macromedia/FlashPlayerTrust

653

Flash Player
SWF HTML
# Flash Player

# Trust files in the following directories:


C:\Documents and Settings\All Users\Documents\SampleApp

HTTP

SMB

.cfg
SWF
Flash Player
[Link] Flash
Player
Flash Player
Flash

Player

Flash Player UI
Flash Player

UI
UI
SWF

Flash Player
UI

654

Flash Player

SWF
SWF

Flash Player


100 KB
ActionScript 3.0
SharedObject

[Link] 652

[Link]/go/settingsmanager_cn

Flash Player
SWF SWF
SWF
Flash Player
Flash

Windowsapp data\Macromedia\Flash Player\#Security\FlashPlayerTrust


C:\Documents and Settings\JohnD\Application Data\Macromedia\Flash
Player\#Security\FlashPlayerTrust
Macapp data/Macromedia/Flash Player/#Security/FlashPlayerTrust
/Users/JohnD/Library/Preferences/Macromedia/Flash Player/#Security/
FlashPlayerTrust

Flash Player

SWF
Flash Player
Flash Player

Flash Player
652

655

Web
Web SWF
XML
SWF
SWF

XML

XML

SWF

SWF

*.[Link]
[Link] [Link] SWF
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*.[Link]" />
<allow-access-from domain="[Link]" />
<allow-access-from domain="[Link]" />
</cross-domain-policy>

SWF Flash Player


SWF

[Link]
SWF [Link]()

[Link]
[Link] 8080 HTTPS [Link]

656

Flash Player

<cross-domain-policy> <allowaccess-from> <allow-access-from> domain

IP (*)
IP

[Link] *.[Link] IP
IP IP IP SWF
[Link] SWF
Flash Player DNS

<?xml version="1.0"?>
<!-- [Link] -->
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

<allow-access-from> secure true


HTTPS HTTPS SWF HTTPS
false
secure false

HTTPS

false Adobe secure

false
HTTPS SWF HTTP
Adobe SWF HTTPS
HTTPS SWF
HTTP secure="false" <allow-access-from>

<allow-access-from domain="[Link]" secure="false" />

<allow-access-from>

ActionScript
Loader Sound URLLoader URLStream ActionScript
URL ActionScript Socket XMLSocket
Flash Player

657

Flash Player
HTTP SWF HTTP
SWF

1024
1024 1024
<allow-access-from> to-ports

XMLSocket
<cross-domain-policy>
<allow-access-from domain="*" to-ports="507" />
<allow-access-from domain="*.[Link]" to-ports="507,516" />
<allow-access-from domain="*.[Link]" to-ports="516-523" />
<allow-access-from domain="[Link]" to-ports="507,516-523" />
<allow-access-from domain="[Link]" to-ports="*" />
</cross-domain-policy>

Flash Player 6

HTTP 80 Flash
Player 9 Flash Player
HTTP
HTTP
[Link]("[Link]

HTTP
HTTP HTTP 1024
HTTP to-ports
674

Flash Player

[Link]() context checkPolicyFile


LoaderContext

<img> <img> checkPolicyFile


"true"<img checkPolicyFile = "true" src = "[Link]">

658

Flash Player

[Link]() context checkPolicyFile


SoundLoaderContext

NetStream NetStream checkPolicyFile

Flash Player
[Link]()


ActionScript API [Link]()
SWF SWF [Link]
SWF
[Link]("[Link]")

SWF 668

670

671

Stage 670 Stage


[Link]() SWF
[Link]() SWF 668


IP [Link]() IP
URL IP
IP [Link]
IP [Link] [Link]("[Link]")
[Link]
* [Link]()
SWF SWF
*

659

ActionScript API [Link]()


[Link]() HTTPS SWF
HTTP SWF
SWF (HTTPS) HTTP

[Link]()
HTTP SWF HTTPS HTTP
HTTP SWF
HTTPS
[Link]() Flash
Player 656 Web

Web SWF
SWF Flash
Player Flash Player
Flash Player SWF

Flash

Player 9

Flash Player Internet SWF


Web
Web
[Link]() SWF
656 Web 659

SWF
Flash

660

Flash Player

Player 9


file: (UNC)
SWF

Flash Player
SWF
SWF URLLoader

SWF
662 SWF
SWF
SWF
[Link]()
SWF
<allow-access-from domain="*"/>
[Link]("*") 656 Web
659
SWF
SWF
652
654 SWF
SWF

Flash /

HTML SWF
ExternalInterface HTML SWF
Flash Player
SWF
SWF SWF
SWF

661

SWF
Adobe Flash CS3
SWF
Flash Flash SWF
SWF
Flash Player Flash Player
652 654

661

[Link]
SWF [Link] Flash Player
SWF Security [Link]

[Link]

SWF Internet URL


Security.LOCAL_WITH_FILE SWF
SWF Internet

Security.LOCAL_WITH_NETWORK SWF

Security.LOCAL_TRUSTED

SWF Internet

SWF Flash
Player SWF
Internet

API

SWF SWF HTML

<object> <embed> allowNetworking


allowNetworking

SWF API
internal SWF API
API
none SWF API
SWF SWF API
API SecurityError

all

662

Flash Player

allowNetworking SWF HTML <object>


<embed> allowNetworking
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="[Link]
[Link]#version=9,0,18,0"
width="600" height="400" id="test" align="middle">
<param name="allowNetworking" value="none" />
<param name="movie" value="[Link]" />
<param name="bgcolor" value="#333333" />
<embed src="[Link]" allowNetworking="none" bgcolor="#333333"
width="600" height="400"
name="test" align="middle" type="application/x-shockwave-flash"
pluginspage="[Link] />
</object>

HTML SWF
allowNetworking Flash Adobe Flex Builder HTML
AC_FL_RunContent() SWF allowNetworking

AC_FL_RunContent( ... "allowNetworking", "none", ...)

allowNetworking "internal" API

navigateToURL()

fscommand()

[Link]()

allowNetworking "none" API API

sendToURL()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

[Link]()

API

663

[Link]()

[Link]()

[Link]()

allowNetworking SWF API



allowNetworking none TextField htmlText <img>
SecurityError
allowNetworking "none"
ActionScript

Flash

Flash Player [Link] Flash


Stage displayState StageDisplayState.FULL_SCREEN
336
SWF
SWF HTML <object> <embed>
allowFullScreen true false
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="[Link]
[Link]#version=9,0,18,0"
width="600" height="400" id="test" align="middle">
<param name="allowFullScreen" value="true" />
<param name="movie" value="[Link]" />
<param name="bgcolor" value="#333333" />
<embed src="[Link]" allowFullScreen="true" bgcolor="#333333"
width="600" height="400"
name="test" align="middle" type="application/x-shockwave-flash"
pluginspage="[Link] />
</object>

HTML SWF
allowFullScreen Flash Flex Builder HTML
AC_FL_RunContent() SWF allowFullScreen

AC_FL_RunContent( ... "allowFullScreen", "true", ...)

ActionScript
Flash Player

664

Flash Player

ActionScript
Esc

Stage SWF Stage


displayState 670 Stage
[Link] FullScreenDisable = 1
652
HTML

SWF

SWF

SWF

SWF

SWF
Loader SWF JPG GIF PNG
SWF SWF
SWF SWF SWF

SWF SWF
SWF
Loader SWF SWF
Loader Loader
Stage
import [Link].*;
import [Link];
var rect:Shape = new Shape();
[Link](0xFFFFFF);
[Link](0, 0, 100, 100);
addChild(rect);
var ldr:Loader = new Loader();

665

[Link] = rect;
var url:String = "[Link]
var urlReq:URLRequest = new URLRequest(url);
[Link](urlReq);
addChild(ldr);

Loader load() context


LoaderContext LoaderContext

SWF
Loader
true Loader 656
Web Loader
Loader SWF ActionScript
[Link] Bitmap
[Link]()
checkPolicyFile

securityDomain

SWF SWF
Loader
securityDomain null
[Link] [Link]
SWF SWF
SWF
SWF SWF

SWF [Link]()
SWF

applicationDomain ActionScript 3.0 SWF


ActionScript 1.0 2.0 SWF

SWF
SWF

securityDomain
SWF applicationDomain
603 ApplicationDomain

362

666

Flash Player

Loader contentLoaderInfo LoaderInfo


LoaderInfo SWF
SWF
[Link] LoaderInfo LoaderInfo
URL
361

SWF SWF
[Link]() [Link]()
[Link]()
SWF
SWF
671

<img> SWF
<img> SWF
<img src = '[Link]' id = 'instanceName' >

TextField getImageReference()

var loadedObject:DisplayObject =
[Link]('instanceName');

SWF
<img>
checkPolicyFile <img>

<img src = '[Link]' checkPolicyFile = 'true' id = 'instanceName' >

<img> SWF [Link]()


SWF
<img> SWF Bitmap
Loader TextField
Loader ActionScript Loader
getImageReference() Loader Loader

667

Loader content
SWF SWF
allowDomain()

RTMP
Flash Media Server (RTMP) SWF
NetConnection connect() RTMP URL
Flash Media Server
Flash Media Server
RTMP [Link]()

[Link]()

ActionScript 3.0 SWF SWF


URL [Link] URL
[Link] SWF SWF

AVM1 SWF AVM2 SWF AVM1 SWF
ActionScript 1.0 ActionScript 2.0 AVM1 AVM2 ActionScript
LocalConnection AVM1 AVM2
ActionScript 3.0 SWF
[Link] [Link] Flash
Player [Link] [Link] [Link] [Link]
[Link]() SWF SWF
[Link]("[Link]") [Link]
[Link] SWF

668

Flash Player


SWF
SWF [Link] [Link] [Link]
[Link]
[Link] / [Link]
SWF

var url:String = "[Link]


var req:URLRequest = new URLRequest(url);
[Link](req);

[Link] = 3;
[Link]();

[Link]("[Link]");

var eggCount:Number;
function DisplayEggs() { ... };
[Link] / [Link]

SWF

[Link]() [Link]
[Link] [Link] [Link] [Link]
[Link]() [Link] SWF
SWF [Link]()
SWF SWF Flash Player SWF
HTML
[Link]() HTML SWF
HTML SWF SWF
[Link]() SWF
659
Flash Player SWF HTML
678

669

Stage
Stage sprite
Stage SWF Stage
SWF

align

showDefaultContextMenu

addChild()

displayState

stageFocusRect

addChildAt()

frameRate

stageHeight

addEventListener()

height

stageWidth

dispatchEvent()

mouseChildren

tabChildren

hasEventListener()

numChildren

textSnapshot

setChildIndex()

quality

width

willTrigger()

scaleMode

Stage SWF
SWF [Link]()
659
frameRate SWF frameRate
Stage [Link]()

Stage removeChildAt() swapChildrenAt()


Stage
[Link]()

SWF SWF
SWF SWF
[Link]() SWF
659
Loader Bitmap
Bitmap SWF
656 Web

670

Flash Player

Loader LoaderInfo
Loader childAllowsParentparentAllowsChild sameDomain

267 10

1.

SWF [Link]()
SWF

2.

SWF [Link]()
SWF

Loader LoaderInfo
Loader childAllowsParent parentAllowsChild

[Link]() [Link]()
SWF

SWF [Link]()

SWF

[Link]() [Link]()
SWF

671


BitmapData draw()
BitmapData MovieClip Bitmap
draw() BitmapData

Sprite MovieClip
draw()
[Link]() SWF

draw()

SecurityError

Loader load() context


LoaderContext LoaderContext checkPolicyFile true
Flash Player
SWF
Bitmap

<img> checkPolicyFile
667 <img> SWF

ActionScript 3.0 API

[Link]()

SWF

[Link]()

SWF

Sound id3

SWF

id3
[Link]()

[Link]()

672

Flash Player

Sound load() context


SoundLoaderContext SoundLoaderContext checkPolicyFile
true Flash Player
SWF
Sound id checkPolicyFile
[Link]()
[Link]() [Link]()

[Link]() stopAll()
[Link]() SWF
stopAll() SWF
[Link]()
computeSpectrum()
SecurityError SWF
SWF [Link]()
SWF MP3 Flash
RTMP
computeSpectrum()
659 656 Web

[Link]()

RTMP

RTMP

[Link]()

FLV

RTMP

[Link]() source [Link]()


FLV FLV
SWF NetStream
checkPolicyFile true

673


SWF ActionScript ActionScript

ActionScript SWF

URLLoader URLStream
XML URLLoader URLStream load()

load() SWF Flash


Player
SWF

XML
1024 SWF

HTTP

80

to-ports
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
SYSTEM "[Link]
<!-- Policy file for xmlsocket://[Link] -->
<cross-domain-policy>
<allow-access-from domain="*" to-ports="507" />
<allow-access-from domain="*.[Link]" to-ports="507,516" />
<allow-access-from domain="*.[Link]" to-ports="516-523" />
<allow-access-from domain="[Link]" to-ports="507,516-523" />
<allow-access-from domain="[Link]" to-ports="*" />
</cross-domain-policy>

674

Flash Player

[Link]()
[Link]() SWF
Flash Player
xmlsocket
[Link]()
[Link]("xmlsocket://[Link]");

[Link]() [Link]()
[Link]() Flash Player

Flash Player

<policy-file-request/>

Flash Player

657

SWF ActionScript
SWF SWF

661
[Link]() URL URL
[Link]() [Link]() [Link]()
[Link]()

675


[Link]()
[Link]() [Link]()
[Link]()

[Link]()

SWF
ActiveX
Flash Player

SWF

SWF
SWF
SWF

SWF
SWF Loader load() context
LoaderContext LoaderContext securityDomain
[Link] Flash Player SWF
SWF
SWF
SWF

SWF SWF SWF


[Link]() SWF
[Link]() SWF
SWF Loader
contentLoaderInfo init SWF
[Link]() SWF
SWF SWF
[Link]() SWF

676

Flash Player


Flash Player 6 Flash Player SWF

SWF [Link]
(www) Flash Player 6 [Link]
[Link] [Link] [Link]
[Link] [Link]
[Link] [Link] SWF

Flash Player 7 SWF


[Link] SWF [Link]
[Link] SWF [Link]

ActionScript 3.0 SWF [Link] true


Flash Player false Flash
Player Flash Player 6 exactSettings
Flash Player

6 SWF
ActionScript 3.0 SWF [Link]
false [Link]()

LocalConnection
LocalConnection SWF LocalConnection
SWF SWF
SWF SWF

LocalConnection

677

LocalConnection SWF SWF


Flash Player SWF LocalConnection
SWF [Link]()
[Link]()
IP *

allowDomain() ActionScript 1.0 2.0


allowDomain() ActionScript 3.0
allowDomain() LocalConnection allowDomain()
[Link]()

SWF LocalConnection domain

ActionScript 3.0 API


[Link]()

[Link]() navigateToURL("javascript:

alert('Hello from Flash Player.')"


[Link]() window _top_self

_parent

[Link]()

SWF SWF

HTML AllowScriptAccess SWF

HTML

SWF PARAM EMBED

AllowScriptAccess "always" "sameDomain" "never"

AllowScriptAccess sameDomain SWF


AVM2

AllowScriptAccess never

AllowScriptAccess always

HTML SWF AllowScriptAccess AVM2


sameDomain

678

Flash Player

HTML AllowScriptAccess
<object id='[Link]' classid='clsid:D27CDB6E-AE6D-11cf-96B8444553540000' codebase='[Link]
flash/[Link]#version=9,0,0,0' height='100%' width='100%'>
<param name='AllowScriptAccess' value='never'/>
<param name='src' value=''[Link]'/>
<embed name='[Link]' pluginspage='[Link]
getflashplayer_cn' src='[Link]' height='100%' width='100%'
AllowScriptAccess='never'/>
</object>
AllowScriptAccess

SWF HTML

SWF AllowScriptAccess="never"
HTML
ActionScript 3.0

[Link]()

[Link]()

ExternalInterface call()

Flash Player SWF


ActionScript RTMP
Flash Player

SharedObject SWF
SWF SWF
URL

SWF

[Link]() [Link]()

localPath

URL SWF
URL SWF '/' localPath

Flash Player
100 KB
652 654

679

[Link]() [Link]() secure


true secure

true Flash Player


HTTPS SWF
SWF [Link]() secure true

false Flash Player


HTTPS SWF

SWF HTTPS URL [Link]()


[Link]() secure true SecurityError
SWF URL
SWF URL
[Link] [Link]
SWF SWF URL URL
SWF URL
[Link]() SWF SWF
URL URL SWF URL ID
[Link] SWF
URL URL URL
URL localPath
Web SWF
URL URL SWF

SWF
HTML SWF
SWF
[Link]() [Link]() null
[Link]/products/flashplayer/articles/thirdpartylso

SWF [Link]() [Link]()


Flash Player
[Link] UI
652
654 [Link]() [Link]()
null [Link]
(true) (false)

680

Flash Player

[Link]()

SWF

getClipboard

Flash

681

682

Flash Player

!== 176
!= 176
$ 180
$ 248
& and 562
( ) XML 308
( ) 87
( ) 248
* , XML 308
* 71, 74, 80
* 248
+= 177, 305
+ 177
+ 248
+ , XMLList 305
, 69
-as3 206
-es 206
. 248
. 86, 105
. , XML 298, 306
.. , XML 306
... (rest) 111
/ 247, 248
: 73
== 176
=== 176
> 91, 176
>= 176
?: 96
@ , XML 298, 308
[ 248
\? 248
\
174
248

] 248
^ 248
__proto__ 56
__resolve 56
| 253

abstract 118
ActionScript
OOP 142
40
42
ActionScript 41
40
56
43
17
43
14
18
18
21

ActionScript 1.0 143


ActionScript 2.0, 144
ActionScript (AVM1) 142
ActionScript 2 (AVM2) 142, 146
ActionScript 234
addCallback() 669
addEventListener() 129, 273, 284
addListener() 273
allowDomain()
img 667
LocalConnection 571
676
668
362
673

683

allowFullScreen 664
allowInsecureDomain() 571
allowNetworking 662
AllowScriptAccess 678
Alpha 357
and (&) 562
application/x-www-form-urlencoded 561
ApplicationDomain 363, 603, 666
apply() 206
arguments 108, 109, 111
[Link] 109
[Link] 111
[Link] 109
Array
concat() 198
join() 198
length 194, 200
pop() 193
push() 193, 207
reverse() 194
shift() 193
slice() 198
sort() 194
sortOn() 194, 196
splice() 193
toString() 198
unshift() 193
206
205
as 76, 132
AS3 148, 206
ASCII 171
avHardwareDisable 653
AVM1Movie 325
AVM1 ActionScript 142
AVM2 ActionScript 2 142, 146
beginGradientFill() 394
big-endian 572
bitmap caching
caching movie clips 351
Bitmap 325, 468
BitmapData , 407
BitmapData 468
Boolean
82
83
Boolean 78
browse() 676
bubbles 277
ByteArray 204

684

call() ExternalInterface 663, 678


callback methods
ignoring 487
callee 109
caller 111
Camera 496
cancelable 275
Capabilities 602
[Link] 653
[Link] 653
catch 223
charAt() 175
charCodeAt() 175
checkPolicyFile 659
childAllowsParent 671
class 117
clearInterval() 166
clearTimeout() 166
clone() BitmapData 473
clone() Event 278
ColdFusion 566
ColorTransform 380
colorTransform 380
computeSpectrum() SoundMixer 668,
671, 672
concat()
Array 198
String 177
connect()
LocalConnection 663
NetConnection 663, 667
Socket 663
XMLSocket 573, 663
content Loader 668
contentLoaderInfo 361, 676
contentType 561
cookie 576
createBox() 379
createGradientBox() 394
CSS
451
450
441
currentDomain 676
currentTarget 278
data URLRequest 561
dataFormat 565
Date
161
162

Date
date 162
day 162
fullYear 162
getMonth() 125, 162
getMonthUTC() 162
getTime() 162
getTimezoneOffset() 163
hours 162
milliseconds 162
minutes 162
month 162
monthUTC 162
parse() 125
seconds 162
setTime() 162
161
159
date 162
Date() 161
day 162
decode() 562
default xml namespace 311
Delegate 282
delete 106, 194
Dictionary
useWeakReference 202
200
dispatchEvent() 285
DisplayObject
stage 273
321, 328
324
DisplayObjectContainer 321, 325, 329
displayState 336, 664
distance() 374
do..while 102
DOM 267, 272
domain LocalConnection 678
download() 663, 676
draw() 362, 666, 668, 671, 672, 673
dynamic 118
E4X XML
ECMAScript for XML XML
ECMAScript 4 56
ECMAScript 232
Endian.BIG_ENDIAN 572
Endian.LITTLE_ENDIAN 572
enterFrame 275
ErrorEvent 229, 286

Event
bubbles 277
cancelable 275
clone() 278
currentTarget 278
eventPhase 277
isDefaultPrevented() 279
preventDefault() 272, 279
stopImmediatePropogation() 278
stopPropogation() 278
target 277
toString() 278
type 275
276
278
275
279
[Link] 561
EventDispatcher
addEventListener() 129, 273
dispatchEvent() 285
IEventDispatch 132
willTrigger() 285
86
eventPhase 277
exactSettings Security 677
exec() 260
extends 134
ExternalInterface 630, 663, 678
[Link]() 669
FileReference 580, 663, 676
FileReferenceList 587, 676
final 75, 127, 129, 138
Flash cookie 576
Flash Media Server 668
Flash Player
6 143
IME 606
286
FLV 503
566
flash 59
Flash , ActionScript 42
Flash , ActionScript 40
Flash FLV
Flash 14
[Link]
319
403
API 387

685

513
465
439
425
543
[Link] 371
flash_proxy 65
Flex, ActionScript

42

FLV
Flash Player 503
Macintosh 505
504
480
for each..in 101, 201, 310
for 100
for , XML 299, 310
for..in 100, 201, 310
frameRate 335
fromCharCode() 175
fscommand() 566, 663, 678
fullScreen 336
fullYear 162
function 117
function 103, 124
[Link]() 206
g 257
GeometricShapes 149
getDefinition() 676
getImageReference() 667
getLocal() 576, 663, 677, 679
getMonth() 125, 162
getMonthUTC() 162
getRect() 378
getRemote() 576, 663, 679
getter setter
139
127
getTime() 162
getTimer() 166
getTimezoneOffset() 163
GIF 360
hours 162
HTML
CSS 450
443
htmlText 443
HTTP 573
i 257
id3 672

686

IDataInput IDataOutput 572


IEventDispatcher 131, 283, 284
if 97
if..else 97
IME
610
607
Flash Player 606
IME
607
608
import 60
indexOf() 178
init 275
instanceof 76
int , 82
int 78
InteractiveObject 325
internal 60, 62, 122
intersection() 378
intersects() 378
is 76, 132
isDefaultPrevented() 279
isNaN() 72
Java 574
join() 198
JPG 360
lastIndexOf() 178
length
arguments 109
Array 194
175
level 286
lineGradientStyle() 394
little-endian 572
load() Loader 362, 658, 663
load() Sound 659, 663, 667, 675
load() URLLoader 561, 663
load() URLStream 663, 675
loadBytes() 362, 658
Loader 360, 663, 672, 676
LoaderContext 658
LoaderContext 362, 666, 672
LoaderInfo
361
671
loaderInfo 361
loadPolicyFile() 663

LocalConnection
connectionName 571
566
677
663
[Link]() 571, 678
[Link]() 571
[Link] 567, 568
[Link]() 663
localFileReadDisable 653
localToGlobal() 374
m 257
Macintosh, FLV 505
match() 179
Matrix
394
, 379
380
380
381
380
380
379
MAX_VALUE Number 79
method URLRequest 561
Microphone 277
milliseconds 162
MIN_VALUE Number 79
minutes 162
month 162
monthUTC 162
MorphShape 325
MouseEvent 272, 279
movie clips
caching 351
MovieClip , 430
MovieClip 325
335
[Link] 282
NaN 79
navigateToURL() 663, 678
NetConnection 663
[Link]() 663, 667
NetStream 659, 663, 667
new 57
null 71, 78, 80, 202

Number
isNaN() 72
79
71
79
82
Number 78
Object
prototype 144, 147
valueOf() 148
199
80
on() 271
onClipEvent() 271
onCuePoint 486
override 127, 128
package 118
parentAllowsChild 671
parse() 125
play() NetStream 663
PNG 360
Point
374
374
374
375
polar() 375
pop() 193
preventDefault() 272, 279
printArea 620
PrintJob , 620
PrintJob() 617
priority , addEventListener() 284
private 120
[Link] 561
protected 121
prototype 144, 147
Proxy 65
public 120
push() 193, 207
Rectangle
376
621
378
378
379
376
376

687

RegExp
260
243
257
replace() 166, 180
rest 111
return 107, 125
reverse() 194
rotate() 380
RSS
536
, 314
RTMP 668
s 257
sameDomain 671
scale() 380
search() 179
seconds 162
Security 663
[Link]()
img 667
676
668
362
673
[Link] 676
[Link] 677
SecurityDomain 362, 666
send() LocalConnection 567, 663
sendToURL() 663, 675
setClipboard() 681
setInterval() 166
setter getter setter
setTime() 162
setTimeout() 166
Shape 325
SharedObject 576, 663
[Link]() 677, 679
[Link]() 679
shift() 193
SimpleButton 325
SimpleClock 166
slice()
Array 198
String 178
Socket 572, 663, 674
Sound 659, 663, 667
SoundFacade 537
SoundLoaderContext 659

688

[Link]()
668, 671, 672
[Link]() 672
splice() 193
split() 179
Sprite 325
sprite, 320, 361
SpriteArranger 365
Stage 273
StageDisplayState 664
static 122
StaticText 326
stopAll() SoundMixer 672
stopImmediatePropogation() 278
stopPropogation() 278
String
charAt() 175
charCodeAt() 175
concat() 177
fromCharCode() 175
indexOf() 178
lastIndexOf() 178
match() 179
replace() 180
search() 179
slice() 178
split() 179
substr() substring() 178
toLowerCase() toUpperCase() 182
String 79
strings
about 172
StyleSheet 450
substr() substring() 178
super 125, 126, 138
SWF
676
360
434
433
602
569
571
switch 99
[Link]() 681
target 277
Telnet 589
test() 260
TextEvent 272
TextField 272, 325

TextFormat 449
TextLineMetrics 463
TextSnapshot 456
this 126, 127, 128, 282
throw 225
Timer
164
540
timer 164
toLowerCase() 182
toString()
Array 198
Event 278
176
toUpperCase() 182
traits 146
Transform
transform 380
translate() 380
try..catch..finally 223
type Event 275
UIEventDispatcher 271
uint , 82
uint 79
undefined 57, 80, 192
Unicode 171
union() 378
unshift() 193
upload() 663, 676
URI 62
URL 562
URLLoader 561
URLLoader
674
663
560
XML 304, 314
[Link] 565
[Link]() 561
[Link] 565
URLRequest 561
[Link] 561
[Link] 561
[Link] 561
[Link] 562
[Link] 562
URLStream 663, 674
URLVariables 560
[Link]() 562
use namespace 64, 66, 149

useCapture , addEventListener() 284


useWeakReference 202
UTC ( ) 161
valueOf() Object 148
var 68, 122
Video 481
void 80
while 102
Wiki 262
willTrigger() 285
WordSearch 552
x 257
XML
ActionScript 296
E4X (ECMAScript for XML) 58, 293, 297
for each..in 101
for 299, 310
306
296
303
299
{ } 304
300
307
307
297
308
294
304, 314
300
312
311
300
574
API 634
295
299, 300
304
307
XML 58
XML { } 304
XML , 307
XMLDocument 59, 298
XMLList
302
305
XMLNode 298
XMLParser 298
XMLSocket 304, 314, 573, 663, 674
[Link]() 573, 663
XMLTag 298

689

allowNetworking 662
img 667
LocalConnection 677
RTMP 668
URLLoader 674
URLStream 674

SWF 676
674
675
677, 679
680
680
677, 680
664
677, 680
667, 672
671
667, 673
680
674
672
672
, 676
670
670

96
95

B
82
114, 128
621

59
60
86
58, 86
58, 59
58
58
72
89
,
0 79

690

671

576
109
149, 206
73

var 68
123
71, 303
24
123
122
68, 73
71
122
123
71
57, 71
69
62
74, 105
Flash Player

535
541
273
496
446
(!=) 176
(!==) 176
351
124

351

108
109
, 108
CSS
, 430
89, 122, 276
134
620
94
, 23
97
91
113
576
, get set 127

ErrorEvent 229, 286


print 618
throw 225
227
216
229
216, 218
222
226
219
228

222
217
221
272
286
217

ActionScript 234
ECMAScript 232
232
229, 286

sprite 320, 361


110
93
93
(.) 248
(.) 86, 105
(.) , XML 298, 306
86
268
358
77, 105, 121
441
69
, 674
and (&) 562
194, 196

26
33
176
199
603
134

90

Rectangle 621
621
616
620
, 623
622
616
616
620
622
617
622
619
618
621
176
91, 176
, 40
355
430
SWF 676
96, 176

F
(\)
174
248

getter setter 127, 139


114, 128
138
124
27
125
126
124
, 369
, 179
87
, Flash Media 668
565
getter setter 139

251

691

97
86
72
79

G
61

Flash Player 677


578, 679
576
578

ActionScript 1.0 143


124
147
88
95
, 549
444, 446
XML 308

199, 200

arguments 108
108
127
110
103
112
107
102
166
113
104, 110
107, 113, 114
103
106, 113
102, 107, 113
104
108
103
248
622
(..) , XML 306
93

692

407
174
174

488

540
335
502
483
427

541

24
33
26
27
36
37
28
26
35
36
134
229
, 81
57, 72
113

372, 388
371
372
166
164

147
140
135
134
(+) 177
(+=) 177
95
(+) 248
, 671
362
URL 362
362

362
360
(^) 248
, Flash Player FLV

680
602
, 199
546
680
, 545
394
, 550
620

132
131
133
133
, 91
87
123
125

XML 300
140
119
141

326
455
441
69
(.)
89

43
40

109

600
599
300
, 430
668

674
checkPolicyFile 362, 672
img 667
securityDomain 666
URLLoader URLStream 674
671
70
549
105, 202

503

dynamic 121
dynamic 118
internal 122
private 120
protected 121
public 120
abstract 118
44
119
117
119
77, 105
61
117
45
134
135
140
77
122
57
119
118
(property) (attribute)
58
26
119
134
47
, 603
56, 145
147
60

73

120

693


73
74
68, 73
80, 82, 312

XML 305
177
(+) , XMLList 305
327
, 36
485

403
405
BitmapData 407
407
, 424
406
407
409
405
407
96

677, 680
533
532
534
(:) 73
273
129
($) 180
($) 248
77

116
116
, 58, 61

AS3 148, 206


flash_proxy 65
namespace 62
use namespace 64, 66, 149
XML 311
64
67

256

N
202
,
57
104,

360
110

694

62, 119
63
61
62
64
63
122

109
57

276
272
273

468
379

Q
94
131

453
441
58
107, 113,
379, 380
379
85

114

LocalConnection 677
499
69
113
113
336, 337, 664

160
160
162
202

S
90
75
, 549
582, 587, 676

677, 680
496
502
499
498
497
441
449, 452
, 326

667, 672
535
535
60
162
161
164
, Flash 40
161, 163
166
, 33
123
126

135
119
668
620
428
428

GeometricShapes 149
Matrix 381
RunTimeAssetsExplorer 434
SimpleClock 166

SpriteArranger 365
Wiki 262
WordSearch 552
369
286
sprite
623
Telnet 589
424
RSS 314
611
API 636
535
505
210
456
262
182

enterFrame 275
init 275
this 282

671
229, 286
268, 285
274
28
272
273
275
268, 273, 276
338
231
271, 486
268
268, 273, 276
268, 273

ActionScript 3.0 273


279
268
283
280
281
285
282

476

695

Macintosh 505
667, 673
478
503
478
483
482
484
485
501
492, 495
505
441
680
, 549

ActionScript 56

XML 300
26
119, 140
113
, ActionScript 3.0 120
257
(@) , XML 298, 308
200
(|) 253

671, 675
565
560
189

Boolean 78
int 78
Number 78
String 79
uint 79
void 80
25
25
57
72
129
252

delete 194
192
193
198

696

190
194
206
179, 192
200
202, 203
192
199
189
199
204
194
204
join() 198
193
204
203
210
190
86, 192
191
201
191
206
200
58
, 259
179
, 350

622
379
347
335
379
191

T
574
572
71

486
485
180

(?:) 96
97
222

179

, Flash Player 286


428
(*) , XML 308

SWF 571
Flash Player 566
SWF 569
87, 199
(UTC) 161
(UTC) 161
219
(URI) 62

672
424
360
444
Bitmap 325
, 360

548
341

API
XML 634
628
628
628
636
630
SWF , 433
, ActionScript 632
, 632
, 560
, 562
537

559
558
662
572
78

672
465
468
467
466
Bitmap

620

351
350
407
350
, 473

340
178

602
447
446
440
454
441
449, 456
440
444, 446
326, 455
442
454
452
179
442
448
454
446
449
43
441, 463

img 667
441
444
IME 609
441
441
444
443
HTML 450
img ,

667

ActionScript 14
Adobe Adobe 16
Flash 14
ActionScript 3.0 13
325

697

(DOM) 3

587, 676
676
, 326
(\?) 248
57, 71
79
199

670
273, 320
, 334
335
321
670

X
, 601
586, 676
80
, 320

670
322
369
329
328
346
368
355
321
403, 405, 409
324
349
API 387
380
324
327
379
379
340
406
353
326
363, 400
338
323
346, 347, 379
329

698

267, 272

358
353
465
355, 379
338
425
543
356
329
327
321, 329

670
333
320
273
326
272
, 360
, 336
320, 388
, 470
471
468
454

XML 308
103
248
87
176
91, 176

(\) 174, 248


(/) 247, 248
86
(*) 71, 74, 80
(*) 248
(*)
, XML
, 349
379
355, 379

308

do..while 102
for 100
for (XML) 299, 310
for each..in 101, 201, 310
for..in 100, 201, 310
while 102
201

105
107
73
81
74
81

351
354
353
353
352
533
CSS
619
90, 94
,
286
219
218
672
, 540
540
174
, 108
80
, 40

428
426
426
425
428
428
335
199, 200
, 601
, 550

543
544
543
, 446
78
549
91
248

213

248
(]) 248
85
, 571
, 492, 495
, 248, 249
, 248
105, 144, 147
56, 144
60

96
95
94
96, 176
97
95
90
93
35
95
96
94
96
90, 94
91
93
, 601

Z
497
141
356

79
247, 248

257
255
247
244
(|)
255
256
260
262
257
252
259
248, 249

253

699

248
247
248
250
254
String 261
dotall 257
extended 257
ignoreCase 257
multiline 257
257
dotall 258
extended 259
global 257
ignore 258
multiline 258
257
255
248
253
, 429

108
68
192
, 549
174
[ ] 105
93

XML 299, 300


36, 88
80, 82, 83
Matrix
231
134

178, 179
177
179
255
LocalConnection
228
44
, 129
, 88

175, 178
248

length 175
176

700

178

568

172
260
XML 312
213
177
, 177, 179
255
173
182
173
175
179
XML 313
182
177, 179
178
199
182
174
174
175
546
, 251
250
250
572

199
86
86, 192

441, 453
441
622
, 254
329
91
248
248
([) 248

69
106, 113
70
113
113, 141

374
372
621

You might also like