Action Script 3.0 Coding
Action Script 3.0 Coding
ActionScript 3.0
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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
12
ActionScript 3.0
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
ActionScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .16
ActionScript
1-4 ActionScript
ActionScript 3.0
ECMAScript 4
ActionScript Adobe
Flash Player 9
ActionScript 3.0
ECMAScript
13
ActionScript 3.0
Adobe Flex
Flex Builder
Builder 2
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 Flash fl
Flash Player API Flash
Flash
Flash
Flash
Flash Web
ActionScript
3.0
ActionScript
3.0
ActionScript 3.0
14
Flash
ActionScript
ActionScript 2.0
ActionScript
2.0
Flash
Flash
2.0
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 ActionScript
Flash
Lite 1.x
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 3.0
ActionScript 3.0
ActionScript AVM2
ECMAScript
(ECMA 262)
ECMAScript (ECMA-262) 4
(API)
17
(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 2.0
ActionScript 3.0 Flash
Player 9
18
ActionScript 3.0
ActionScript 3.0
ActionScript 3.0
ActionScript 2.0
[Link]
ActionScript 3.0
ECMAScript (ECMA-262) 3
ActionScript 3.0
ActionScript 3.0
19
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
20
ActionScript 3.0
API ActionScript
URLStream URLLoader
ByteArray
Sound API SoundChannel SoundMixer
API SWF
SWF
21
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
ActionScript 3.0
ActionScript 3.0
ActionScript 3.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
24
ActionScript
ActionScript
String
Numeric numeric ActionScript 3.0
Number
Int
Uint
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;
[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.
31
b.
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>;
34
ActionScript
new
new
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
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);
gotoAuthorPage() URL
[Link] URLRequest URL navigateToURL()
URL
3.
[Link]([Link], gotoAuthorPage);
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
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
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.
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
{
//
}
127 get set
ActionScript EventDispatcher
267 10
46
ActionScript
ActionScript ActionScript 3.0
ActionScript 3.0
.as
Adobe
.as
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;
}
}
}
48
ActionScript
ActionScript
Greeter
Flash Flex
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
HelloWorld
Flash ActionScript
Flash >
ActionScript HelloWorld
1.
2.
[Link]
[Link]
49
3.
Hello,
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."
ActionScript
Flash Flex
Flash
1. [Link]
2.
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
Flash
Flash
Flash
1.
2.
outputText appendText()
3. trace()
4. trace()
appendText()
5. >
SWF
trace()
trace()
trace() trace()
53
trace()
trace()
trace() trace()
trace()
TextField appendText()
ActionScript
outputText 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
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
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
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 {}
public internal
public
59
ActionScript 2.0
SampleCode
SampleCode
ActionScript 2.0
samples
import samples.*;
import [Link];
(SampleCode)
([Link])
SampleCode
SampleCode
internal
60
ActionScript
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
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
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
private
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
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
// 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
// [ 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;
new CustomClass
customItem
var customItem:CustomClass = new CustomClass();
(,)
3
var a:int, b:int, c:int;
3 ab c
ActionScript 3.0
strGlobal
69
localScope() str2
function localScope()
{
var strLocal:String = "local";
}
localScope();
trace(strLocal); // strLocal
str1 scopeTest()
trace trace
70
ActionScript
num trace()
num
trace(num); // NaN
var num:Number = 10;
trace(num); // 10
num = 5;
trace(num); // 5
var num:Number = 10;
trace(num); // 10
Boolean
false
int
Number
NaN
Object
null
String
null
uint
undefined
null
IEEE-754
*
undefined
null
71
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
(:)
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
ClassBase ClassExtender
ClassExtender someString
ClassBase ActionScript 3.0 myClass
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
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
78
ActionScript
Number Number
Number
64 265-1 11
Number 21023
Number 52
52 1/3
Number 52 Number
52 -9,007,199,254,740,992 (-253)
9,007,199,254,740,992 (253)
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
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; //
81
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
trace(Number("044"));
// ActionScript 3.0 44
// ActionScript 2.0 36
82
ActionScript
Number int
uint
Boolean
true 1 0
Date
Date 1970 1 1
null
Object
String
Flash Player
Number NaN int uint 0
undefined
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
// null
// false
//
// false
Boolean
Boolean
//
Boolean
Boolean
String
null
false
Object
84
ActionScript
String
String
String true "true" false
"false"
Array String
String
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"
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]
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
172 244
303 XML
(;)
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
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
MINIMUM
MAXIMUM
class A
{
public const MINIMUM:int = 0;
public const MAXIMUM:int;
public function A()
{
MAXIMUM = 10;
}
}
89
MAXIMUM
class A
{
public const MINIMUM:int = 0;
public const MAXIMUM:int;
}
var a:A = new A();
a["MAXIMUM"] = 10; //
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
(())
(?:)
(<) (>)
true 3 2 true
1
trace((true) < 1);
true 1
false 1 1
91
false 2 1 false
3
trace(3 > (false));
false 0 3
true 3 0
trace(3 > 0); // true
ActionScript 3.0
x++ x--
* / %
+ -
== != === !==
&
&&
||
?:
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]()
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
100
ActionScript
for each..in
XML XMLList
for
each..in for..in for each..in
for each..in
XML
XMLList
101
while
while if true for
var i:int = 0;
while (i < 5)
{
trace(i);
i++;
}
do..while
do..while while
do...while
var i:int = 5;
do
{
trace(i);
i++;
} while (i < 5);
// 5
ActionScript 3.0
ActionScript
102
ActionScript
(())
trace() Flash Player API
[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 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
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
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
arguments
arguments
arguments
arguments
[Link]
[Link]
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);
//
...(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
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
OOP
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
GeometricShapes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
(OOP)
115
OOP
OOP
get
set
(Attribute)
private public
(Class)
(Constructor)
(Data type)
(Enumeration)
(Class hierarchy)
(Inheritance) OOP
(Instance)
(Namespace)
116
ActionScript
trace() 53
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)
118
ActionScript
API Accessibility
ActionScript 3.0
hello() trace
function hello():String
{
trace("hola");
}
class SampleClass
{
hello();
trace("class created");
}
//
hola
class created
119
(property) (attribute)
ActionScript
ActionScript 3.0
getter setter
ActionScript 3.0 (property)
(attribute)
internal
private
protected
public
static
UserDefinedNamespace
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
(.)
([])
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
121
internal (attribute)
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
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;
}
trace([Link]); // 0
trace(StaticVars.MAX_NUM); // 16
// !!
class StaticVars2
{
public static const UNIQUESORT:uint;
function initializeStatic():void
{
UNIQUESORT = 16;
}
}
123
function
public function sampleFunction():String {}
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
[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
get set
get set getter setter
get set
getPropertyName()
setPropertyName()getter setter
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
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"
final
129
ActionScript
if ([Link] == [Link]) //
if ([Link] == "portrai") //
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]();
131
useCapture:Boolean=false):void;
function dispatchEvent(event:Event):Boolean;
function hasEventListener(type:String):Boolean;
function willTrigger(type:String):Boolean;
}
IEventDispatcher EventDispatcher
IeventDispatcher
is
as
132
ActionScript
IExample IExternalizable
public interface IExample extends IExternalizable
{
function extra():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
Event
Event complete connect
135
Event
function
function
function
function
stopPropagation():void {}
stopImmediatePropagation():void {}
preventDefault():void {}
isDefaultPrevented():Boolean {}
Event Event
Event MouseEvent
mouseMove click
MouseEvent
public public
private protected internal
private
ActionScript private
ActionScript 3.0 protected
protected
136
ActionScript
internal
internal
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;
}
}
}
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 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;
}
143
Shape Circle
[Link]
[Link]
[Link]
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
prototype
dynamic
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
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
GeometricShapes
GeometricShapes ActionScript 3.0
override
GeometricShapes
149
[Link]/go/learn_programmingAS3samples_flash_cn
Samples/GeometricShapes GeometricShapes
[Link]
[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
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()
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
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
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()
IGeometricShape
IGeometricShape Circle Square
describe()
[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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
159
ActionScript
ActionScript Timer
Date
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
getTime() setTime()
Date
Date
162
getTime() setTime()
30
Date
//
var invoiceDate:Date = new Date();
// 30
var dueDate:Date = new Date([Link]() + (30 * millisecondsPerDay));
millisecondsPerDay 30
invoiceDate dueDate
30
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
3.0
Timer
ActionScript 3.0 Timer ([Link])
Timer
60 Timer
var oneMinuteTimer:Timer = new Timer(1000, 60);
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
setInterval(closure:Function,
delay:Number, ... arguments):uint
setTimeout(closure:Function,
delay:Number, ... arguments):uint
Timer
[Link]/go/learn_programmingAS3samples_flash_cn
Samples/SimpleClock SimpleClock
[Link]
[Link]
com/example/programmingas3/
simpleclock/[Link]
com/example/programmingas3/
simpleclock/[Link]
166
SimpleClock
SimpleClock SimpleClock
AnalogClockFace
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
ActionScript
"Hello"
"555-7649"
"[Link]
String
172
ASCII ASCII
26
(Character)
(Concatenation)
(String)
(Substring)
Unicode Unicode
trace() 53
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");
ActionScript (') ( )
ActionScript
(\)
\b
\f
\n
\r
\t
\unnnn
\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
== !=
toString()
+ String toString()
String() toString()
176
+=
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()
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()
243 9 ActionScript
3.0
String
match() search()
replace()
243 9
search()
var str:String = "The more the merrier.";
//
trace([Link]("the")); // 9
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()
i (ignoreCase)
g (global)
243 9
$ $
$$
$&
$`
(`)
(') ()
$'
()
180
$n
n n 1-9 $n
$nn
nn nn (01-99)
nn
$2 $1
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()
str = [Link]();
a-z A-Z
var str:String = "Jos Bara";
trace([Link](), [Link]()); // JOS BARA jos bara
ASCII
ASCII
String split()
getCharAt()
ASCII
182
ASCII
ASCII Courier
New ASCII
ASCII
[Link]/go/learn_programmingAS3samples_flash_cn
Samples/AsciiArt ASCIIArt
[Link]
[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()
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;
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
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()
oceans
193
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
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
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
196
[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()
198
Object
monitorInfo
Object
var monitorInfo:Object = new Object();
aspect ratio
199
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 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]
*/
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; //
tasks
202
masterTaskList Array
0 6
masterTaskList
2 1
trace(masterTaskList[2][1]); // dentist
6
0
trace(masterTaskList[6][0]); // mow lawn
203
trace([Link][1]); // dentist
trace([Link][0]);
// mow lawn
for..in
masterTaskList
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
205
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()
TypedArray
push() for..in args
push() passArgs TypedArray
push() TypedArray concat()
208
splice()
splice() 2 args
for splice()
args Array TypedArray
[Link]() for..in args
2 splice()
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]
[Link]
com/example/programmingas3/playlist/
[Link]
PlayList
Song
com/example/programmingas3/playlist/
[Link]
Song
Song
PlayList
PlayList Song addSong()
sortList()
songListPlayList Array
210
_songs
sortList()
PlayList addSong()
/**
*
*/
public function addSong(song:Song):void
{
this._songs.push(song);
this._needToSort = true;
}
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");
//
[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
PlayList
213
214
ActionScript 3.0
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .222
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .223
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .228
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .232
CustomErrors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .236
215
SWF
55
3 ActionScript 115 4 ActionScript
if..then..else
ActionScript
ActionScript
ActionScript
Flash Player
216
(Asynchronous)
(Catch)
Flash Player ActionScript
(Exception) Flash
(Re-throw)Flash Player
(Synchronous)
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()
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
220
ActionScript 3.0
ActionScript 3.0
ActionScript 3.0
MemoryError ArgumentError
URIError
232
Flash Player
Flash Player
upload() [Link]() false
ActionScript 3.0 upload()
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]();
}
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..catch..finally
try
{
//
}
catch (err:Error)
{
//
}
finally
{
//
//
}
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]);
}
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);
}
}
}
}
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
227
ActionScript
Flash Player
Error try..catch
toString()
lookupErrorString()
AppError
ActionScript Error
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
package
{
import
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
229
230
level Flash Player [Link]
[Link] [Link] NetConnection
NetStream SharedObject [Link] HTTPStatusEvent
Camera Microphone LocalConnection level
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
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);
}
}
}
ECMAScript
ECMAScript Error EvalError RangeError ReferenceError
SyntaxError TypeError URIError
Error
Error
ECMAScript
EvalError RangeError
ReferenceError SyntaxError
TypeError URIError
EvalError
Function
eval() EvalError
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
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]
[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
validateEmployeeXML()
CustomErrors
237
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;
}
238
Alert
Yes FatalError
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
FatalError
FatalError ApplicationError FatalError
getTitle() toString() FatalError
errorID ApplicationError
ApplicationError getMessageText() FatalError
toString()
toString()
ApplicationError toString()
CustomErrors
241
WarningError
WarningError ApplicationError
[Link]
public function WarningError(errorID:int)
{
id = errorID;
severity = [Link];
message = [Link](errorID);
}
242
FatalError
[Link]
/A\d+/
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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
7 10
a m
244
(Escape character)
(\)
(Flag)
(Metacharacter)
(Quantifier)
5 9
(Regular expression)
1.
Flash
2.
3.
RegExp
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
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
(\) 1/2
var pattern:RegExp = /1\/2/;
new (\)
String 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
^ $ \ . * + ? ( ) [ ] { } |
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
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
\v
\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-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
word word-word-word
/\w+(-\w+)*/
.*
<p>...</p>
<p>Paragraph 1</p>
(?)
*? <p> </p>
/<p>.*?<\/p>/
252
{0} {0,0}
/abc+*/
s (dotall)
(.)
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
252
254
(|)
(|)
var pattern:RegExp = /cat|dog/;
// cat dog
pattern = /ca(t|d)og/;
// catog cadog
\1
\1, \2,
... , \99 99
(?:
)
var pattern = /(?:com|org|net);
(com|org) exec()
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
global
ignoreCase
A-Z a-z
multiline
$ ^
dotall
. (\n)
extended
gims
x
var re:RegExp = /abc/gimsx;
false
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)
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()
259
lastIndex 0
0
5
11
18
25
36
44
source
source
var pattern:RegExp = /foo/gi;
trace([Link]); // foo
test()
RegExp
test()
260
exec()
RegExp exec()
index
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
[Link]/go/learn_programmingAS3samples_flash_cn WikiEditor
Samples/WikiEditor
[Link]
[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()
262
Wiki
Test WikiParser
parseWikiString() HTML
HTML
<b>foo</b>
private function parseBold(input:String):String
{
var pattern:RegExp = /'''(.*?)'''/g;
return [Link](pattern, "<b>$1</b>");
}
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>
^ $ m (multiline)
^
replace() ("") g
(global) replace()
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
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
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
(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
ActionScript 3.0 ActionScript
onClipEvent() MovieClip
[Link] [Link]
addListener()
DOM
UIEventDispatcher
on() onClipEvent()
this
ActionScript 3.0
271
ActionScript 3.0
ActionScript 3.0
(DOM) 3 SWF
DOM
DOM DOM
272
ActionScript 3.0
ActionScript 2.0 addListener() ActionScript 2.0
ActionScript 3.0
ActionScript 2.0
ActionScript 3.0
[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
274
enterFrame
init
Socket
API
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()
Event
Event Event
Flash Player API Event
Event MouseEvent 10
Event 10
Event MouseEvent
click doubleClick mouseDown mouseUp
clone() toString()
Flash Player
Flash Player
addEventListener()
279
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
281
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);
}
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
addEventListener()
IEventDispatcher
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]
[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
288
//
[Link] = [Link](1000, [Link] - [Link]);
[Link]();
return alarmTime;
}
Date (alarmTime)
alarmTimer reset()
alarmTime now
Timer timer
alarmTimer delay start()
Timer timer TimerEvent
([Link]) Event Timer
TimerEvent
Timer AlarmClock
ActionScript
[Link] [Link]
IEventDispatcher EventDispatcher
AlarmClock SimpleClock SimpleClock Sprite Sprite
EventDispatcher AlarmClock
Alarm Clock
289
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 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
XML
XML
295
XML
XML
Web
XML
XML ActionScript
ActionScript 3.0 XML
XML
ActionScript
XML
XML
XML
XML
XML
XML
XML
XML
296
XML
String
(Element)XML
XML
(Empty element)
<element/>
(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 (.)
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
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
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
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>
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
XML XMLSocket
ActionScript 3.0 XMLSocket
XML
prependChild() appendChild() XML
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 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>
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
XMLList
XMLList
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'));
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/
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
312
XML
XML
new XML()
XML
XML
XML XML
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
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>
[Link]/go/learn_programmingAS3samples_flash_cnRSSViewer
Samples/RSSViewer
[Link]
[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
RSS
xmlLoaded()
rssTitle = [Link]();
xmlLoaded()
dataWritten = new Event("dataWritten", true);
Internet RSS
317
318
XML
12
12
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .324
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .326
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .328
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .339
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .356
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .358
SpriteArranger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .363
319
ActionScript 3.0
Stage
Stage
SWF
320
DisplayObject stage
334
ActionScript 3.0
[Link] DisplayObject
326
Bitmap Bitmap
Loader
JPEG
Shape
ActionScript
Shape
Drop Shadow
TextField
DisplayObjectContainer
DisplayObject DisplayObject
Shape Video DisplayObject
321
ActionScript
SWF
371 13
403 15
425 16
TextField 439 17
465 18
477 19
322
Alpha Alpha
60% 60% 40%
(Bitmap graphic)
(Blending mode)
(Masking)
(Stage)
(Transformation)
(Vector graphic)
SWF
323
Flash Player
Flash
1.
2.
3.
4. >
trace()
53
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]
Shape Shape
387 14 API
TextField [Link]
439 17
Video [Link]
477 19
[Link] DisplayObject
325
2.0
MovieClip Shape
ActionScript 3.0
Shape MovieClip Shape Flash
Player MovieClip
ActionScript 3.0
326
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 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
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()
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
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
StageScaleMode.EXACT_FIT
StageScaleMode.SHOW_ALL
SWF
StageScaleMode.NO_BORDER
// videoScreen
//
// SWF
//
//
//
//
controlBar Sprite
videoScreen
SWF
import
import
import
import
[Link];
[Link];
[Link];
[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];
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
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 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);
//
//
//
//
import [Link];
import [Link];
var offsetX:Number;
var offsetY:Number;
var draggedObject:DisplayObject;
//
function startDragging(event:MouseEvent):void
{
//
draggedObject = DisplayObject([Link]);
//
// x, y
//
343
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);
width height
scaleX scaleY
width height
//
[Link] = 420;
[Link] = 420;
//
var radius:Number = [Link] / 2;
height width
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 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
357
349
SWF
opaqueBackground
Adobe Illustrator
opaqueBackground true
scrollRect
Flash
Web cacheAsBitmap
true
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;
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
ColorTransform
ColorTransform [Link]
var colorInfo:ColorTransform = my [Link];
//
//
[Link] = colorInfo;
// 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%
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;
//
// 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
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
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
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
603 ApplicationDomain
SWF Loader
SWF Loader
ActionScript 3.0
LoaderContext
SpriteArranger
SpriteArranger GeometricShapes
149 GeometricShapes
SpriteArranger
SpriteArranger
363
[Link]/go/learn_programmingAS3samples_flash_cn
Examples/SpriteArranger SpriteArranger
[Link]
[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
DrawingCanvas()
Rectangle bounds
initCanvas()
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
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
DrawingCanvas addShape()
GeometricSprite GeometricSprite
366
break;
case "Circle":
newShape = new CircleSprite(len);
break;
}
[Link] = 0.8;
[Link](newShape);
}
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
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
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
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
(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)
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
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
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
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
DisplayObjectTransformer Matrix
381
-45 50%
[Link]/go/learn_programmingAS3samples_flash_cn
Samples/DisplayObjectTransformer DisplayObjectTransformer
[Link]
[Link]
com/example/programmingas3/geometry/
[Link]
img/
MatrixTransformer
MatrixTransformer Matrix
transform()
transform()
sourceMatrix
xScale yScale
dx dy
rotation
382
x y
x y
skew
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]()
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
(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
lineStyle() lineGradientStyle()
lineStyle()
Alpha myShape Shape 2
(0x990000) 75%
[Link](2, 0x990000, .75);
lineGradientStyle() 393
beginFill() beginGradientFill()
beginBitmapFill() beginFill()
Alpha
myShape
[Link](0x00FF00);
390
API
Graphics
Graphics (0, 0)
moveTo()
lineTo() curveTo()
moveTo()
lineTo() Graphics
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
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
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]
[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;
396
API
Graphics
Graphics
Graphics drawRect()
drawRect() 50100 150beginGradientFill()
100
50
lineGradientStyle() beginGradientFill()
lineStyle()
397
Math
Graphics
Math Math
[Link] 3.14159265...
[Link]() [Link]() [Link]()
Math Math
[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
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
i visibleSatellites
doEveryFrame() visibleSatellites
ControlPanel
changeSetting()
doEveryFrame()
401
API
doEveryFrame()
doEveryFrame()
Math
API Flash
API ActionScript
402
API
15
15
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 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);
myDisplayObject
filters
null
[Link] = null;
filters 407
406
BitmapData
BitmapData
BitmapData applyFilter()
[Link](sourceBitmapData);
applyFilter()
BitmapData
BitmapData
applyFilter()
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
cacheAsBitmap
408
ActionScript 3.0 9 BitmapData
BevelFilter
BlurFilter
DropShadowFilter
GlowFilter
GradientBevelFilter
GradientGlowFilter
ColorMatrixFilter
ConvolutionFilter
DisplacementMapFilter
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.
Player
2.
Flash Player x
Flash Player
0xFF 255
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
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
425
ActionScript
ActionScript
ActionScript
SWF
ActionScript
Flash Player
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]()
Flash
MovieClip MovieClip ActionScript
Flash
MovieClip SWF
ActionScript [Link]
427
play() stop()
bicycle
[Link]();
startButton
//
//
function playAnimation(event:MouseEvent):void
{
[Link]();
}
//
[Link]([Link], playAnimation);
428
1 prevFrame() nextFrame()
1 prevFrame()
if
gotoAndPlay() gotoAndStop()
ActionScript
ActionScript
429
Flash SWF
gotoAndPlay() gotoAndStop()
FLA
Flash
ActionScript MovieClip
Flash
ActionScript
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
Flash
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);
}
SWF
ActionScript 3.0 SWF
ActionScript 4
1.
Loader SWF
URL URLRequest
2.
Loader
3.
4.
SWF
433
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
RuntimeAssetsExplorer
ActionScript
ActionScript SWF SWF
SWF Flash SWF
SWF SWF
434
[Link]() SWF
ActionScript
ActionScript
MovieClip
SWF 660
[Link]/go/learn_programmingAS3samples_flash_cn RuntimeAssetsExplorer
Samples/RuntimeAssetsExplorer
[Link]
[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()
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
TextFormat
HTML StyleSheet
TextFormat StyleSheet
TextFormat
449
HTML 443
HTML
450
[Link]
HTML
CSS
440
[Link]
ActionScript
HTML
(Device font)
(Dynamic
(Static text
ActionScript
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
XML Web
442
[Link]
447
442
[Link]
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;
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
[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
446
TextFormat
TextFormat 452
myTextBox
textInput textInputCapture
Flash Player myOutputBox
package
{
import
import
import
import
[Link];
[Link];
[Link].*;
[Link].*;
447
[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
449
HTML text
HTML htmlText
CSS CSS
CSS
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];
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;
}
}
}
[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
SWF
CSS
SWF
TextField
453
Flash
Flash TrueType Type 1
Postscript
Flash
TextField
Flash
Flash
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
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
TextSnapshot SWF
ActionScript
TextField
CSS
CSS
TextLineMetrics
TextFormat
[Link]/go/learn_programmingAS3samples_flash_cn
Samples/NewsLayout
[Link]
[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
TextFormat HeadlineTextField
onCSSFileLoaded() getTextStyle()
getTextStyle()
458
[Link],
[Link],
[Link],
[Link],
[Link]);
if ([Link]("letterSpacing"))
{
[Link] = [Link];
}
}
return format;
}
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
shrinkText() growText()
461
MultiColumnTextField TextField
MultiColumnTextField()
TextField
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>";
}
}
464
18
18
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .465
Bitmap BitmapData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .468
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .470
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
RGB
0 255
255 102 0
465
16 48
48 16
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
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
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
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];
[Link]()
[Link]()
firstPoint
(Point) BitmapData
firstAlphaThreshold
(uint) Alpha
(Object)secondObject Rectangle
Point Bitmap BitmapData
secondBitmapDataPoint (Point) BitmapData
secondObject BitmapData
secondObject
null
471
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
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
[Link](movieClip);
transform
BitmapData Bitmap transform
473
noise() perlinNoise()
noise()
randomSeed
(int)
[Link]()
(uint) 0 255 0
low
channelOptions (uint)
ARGB 7
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
(Boolean) true
false
grayScale
fractalNoise
(Boolean)grayScale noise()
true randomSeed
false
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
ActionScript
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
Flash FLV
FLV Flash
CD-ROM FLV
Flash
FLV
Video
Video SWF
[Link]() Video HTTP
FLV Video
NetConnection
FLVPlayback
Video Video
Video
481
NetStream NetConnection
1.
NetConnection Adobe
Flash Media Server 2 Adobe Flex FLV NetConnection
connect() null HTTP FLV
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.
Flash
482
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)
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);
486
#2095:
#2095:
#2095:
#2095:
[Link]
[Link]
[Link]
[Link]
onMetaData
onCuePoint
onCuePoint
onCuePoint
NetStream client
NetStream
NetStream
NetStream client
Object
this
onMetaData onCuePoint
onMetaData metaDataHandler()
Flash Player onCuePoint
onCuePoint onMetaData
487
NetStream client CustomClient
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
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");
}
}
}
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
NetStream
NetStream onCuePoint onMetaData
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);
}
}
}
490
{
trace("metadata");
}
function cuePointHandler(infoObject:Object):void
{
trace("cue point");
}
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
parameters:
name: point1
time: 0.418
type: navigation
onCuePoint onMetaData
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
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
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 ");
}
498
Flash Player
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()
function statusHandler(event:StatusEvent):void
{
switch ([Link])
{
case "[Link]":
trace(" ");
break;
case "[Link]":
trace(" ");
break;
}
}
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);
}
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");
}
502
Video Camera Flash Media
Server
Video on Demand Web
mp3
Flash Media Server [Link]
Sorenson Spark
On2 VP6
SWF
Flash Player
6 7 8
7, 8
8*
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
504
Macintosh FLV
Apple Macintosh (/)
FLV CD-ROM
Flash Player
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();
}
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);
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)
{
//
}
}
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()
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
ActionScript
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)
(Buffering)
(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
516
[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 Sound
Sound
Sound
var req:URLRequest = new URLRequest("click.mp3");
var s:Sound = new Sound(req);
517
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];
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
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
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
ActionScript
[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]
[Link]
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
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
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
526
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
[Link]()
SoundChannel [Link]()
SoundChannel
ByteArray 512
-1 1
256
528
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];
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]()
532
[Link] [Link]
[Link]
[Link] true
false StatusEvent Microphone muted
[Link] [Link]
true [Link]()
true
[Link]()
Adobe [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
trace
ActionScript
Microphone NetStream
Flash Flex
MovieClip Video
[Link] Flash Media Server
Podcast Player
Internet
mp3
mp3
Podcast Player
535
RSS XML
SoundFacade
[Link]
[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 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
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()
538
Sound
Sound SoundLoaderContext bufferTime
url SoundFacade
load()
url load()
SoundFacade
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]();
}
}
}
Timer
SoundFacade Timer
[Link]() Timer
TimerEvent onPlayTimer()
TimerEvent
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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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
SWF
InteractiveObject Sprite MovieClip
square
Sprite square Stage
Stage
localX localY
square
[0,0] square stageX stageY
[50,50] square
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
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);
}
SimpleButton true
true
MovieClip true
FocusEvent.FOCUS_IN FocusEvent.FOCUS_OUT
sprite
InteractiveObject Tab
Flash
SWF Flash
550
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()
[Link] for
Button
WordSearch
553
isLegalContinuation()
isLegalContinuation() true
searchForWord()
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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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
(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
[Link] application/x-www-form-urlencoded
[Link]()
URLLoader
URLRequest URLRequest HTTP
URL GET POST MIME
XML
XML ActionScript 3.0
request
561
URL
URLVariables
[Link]()
URLVariables
URLVariables [Link]()
and URL
& %26 URL
ActionScript 3.0
ActionScript
ActionScript
[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
URLVariables
- URLVariables
-
[Link]()
var dayNameArray:Array = [Link](",");
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];
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];
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
565
catch (error:Error)
{
trace("Unable to load URL");
}
function completeHandler(event:Event):void
{
trace([Link]);
}
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
566
LocalConnection LocalConnection
ActionScript 3.0
send() connectionName LocalConnection
allowDomain() domain
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 {}
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
[Link]("conn1", "doQuit");
570
SWF
LocalConnection allowDomain()
allowInsecureDomain() LocalConnection
ActionScript [Link]()
[Link]()
ActionScript 3.0 [Link]()
[Link]()
[Link]() [Link]()
[Link]() [Link]()
* localhost (*)
localhost SWF SWF
Flash Player
571
ActionScript 3.0 XML
XML
XML XML
XML
XML XML
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
XMLSocket
ActionScript XMLSocket
HTTP HTTP
XMLSocket
SWF
Java Python Perl
XMLSocket XMLSocket
TCP/IP XML
XML
XML (0)
XMLSocket XML
XMLSocket
[Link]() SWF
SWF [Link]()
SWF
XMLSocket
URLLoader XMLSocket
573
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
[Link] Java
[Link] Java
java SimpleServer XMLSocket
[Link] Web
575
[Link]()
1024 securityError ([Link])
data ([Link])
[Link]([Link], onData);
private function onData(event:DataEvent):void
{
trace("[" + [Link] + "] " + [Link]);
}
IOError
XML (\n)
Flash cookie
Web
[Link]() [Link]()
getLocal()
getRemote() Flash Media Server
getLocal() getRemote()
SharedObject
test
576
test 0
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]();
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
SharedObject
getLocal() getRemote() SharedObject secure
HTTPS SWF
true SWF HTTPS Flash Player
HTTPS SWF SWF [Link]()
secure true false SWF HTTPS
Flash Player
578
FileReference
Windows
ActionScript FileReference
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
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,,,)
581
browse()
[Link]()
[Link]() Flash Player
[Link] [Link]()
[Link]()
[Link]()
FileFilter browse()
[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]
[Link]
SecurityErrorEvent.SECURITY_ERROR
HTTPStatusEvent.HTTP_STATUS
IOErrorEvent.IO_ERROR
HTTP
Flash Player /
SWF
Flash Player
url [Link]() HTTP HTTPS
ColdFusion
Flash Player
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;
}
}
?>
URLVariables
ActionScript
ActionScript 3.0 URLRequest
POST GET
GET POST [Link]
[Link] [Link]
ActionScript 3.0 upload() Filedata
Custom1 Filedata
Flash Player true
upload()
585
[Link]()
request defaultFileName URLRequest
URL
defaultFileName URL
SWF
[Link]
defaultFileName
URL
defaultFileName
download()
URL ActionScript 3.0 ColdFusion
package
{
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
586
{
trace("Unable to download file.");
}
}
}
}
ColdFusion
[Link] URL
FileReferenceList
FileReferenceList
[Link]()
FileFilter imageFilter textFilter
[Link]()
587
FileReferenceList
[Link]() FileReferenceList
[Link]()
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
ta TextArea
Telnet
state Telnet
Telnet connect()
590
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
[Link]/go/learn_programmingAS3samples_flash_cn Samples/FileIO
FileIO
[Link]
[Link]
com/example/programmingas3/fileio/
[Link]
com/example/programmingas3/fileio/
[Link]
592
FileIO
FileIO Flash Player
FileUpload FileDownload
[Link]
contentComplete init() ProgressBar
Button
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);
}
595
progress
([Link]) progress progressHandler()
ProgressBar progressHandler()
/**
*
*/
private function progressHandler(event:ProgressEvent):void
{
[Link]([Link], [Link]);
}
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
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()
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
ActionScript
DPI
mp3
Flash Player
SWF
IME
IME
IME
IME
IME
(Operating system)
Microsoft Windows Mac OS X Linux
(Clipboard)
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
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
Capabilities
Capabilities SWF Capabilities
Flash Player
Capabilities
[Link] [Link]
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
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] = "[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 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
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;
}
}
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
ExternalInterface
[Link]/go/learn_programmingAS3samples_flash_cn
Samples/CapabilitiesExplorer CapabilitiesExplorer
[Link]
[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;
}
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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .623
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .625
615
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()
}
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
[Link]() [Link]()
[Link]() [Link]()
[Link]() [Link]()
15 PrintJob [Link]()
false PrintJob [Link]() Flash Player
620
617
sprite
sprite
Flash Player
Rectangle addPage()
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;
}
622
sprite sheet1 sheet2
sprite [Link]()
package
{
import
import
import
import
import
import
import
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
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];
625
trace(">>
trace(">>
trace(">>
trace(">>
try
{
[Link](this, new Rectangle(0, 0, 100, 100));
}
catch (error:Error)
{
//
}
[Link]();
}
else
{
[Link]
}
// txt
[Link]
[Link]
= 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
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .628
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
ExternalInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .636
API ActiveX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .642
627
API
API
SWF SWF
SWF SWF
HTML SWF
SWF
HTML SWF
API
API
ActionScript
ActionScript
ActionScript
628
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]
API
ExternalInterface
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()
ActionScript
ExternalInterface
ActionScript ActionScript
JavaScript ActionScript
ExternalInterface
ActionScript
ActionScript
ExternalInterface
631
[Link]
Flash Player
true false ExternalInterface
if ([Link])
{
// ExternalInterface
}
[Link] ExternalInterface
JavaScript
ActionScript
[Link]()
[Link]()
// addNumbers
//
// result
var param1:uint = 3;
var param2:uint = 7;
var result:uint = [Link]("addNumbers", param1, param2);
632
API
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
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]
[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
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()
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");
[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()
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
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]
ExternalInterfaceProxy/
[Link]
ExternalInterfaceProxy/
[Link]
C#
ExternalInterfaceProxy
ActionScript
642
API
ExternalInterfaceProxy/
[Link]
ActionScript
ActiveX
bin/Debug/[Link]
SWF
obj/[Link],
obj/[Link]
Introvert IM C#
SWF
Windows Forms Shockwave Flash ActiveX
ActionScript IM SWF
Windows Forms IM (MessageText)
(Transcript) SWF IM
(Status)
Windows Forms
Visual Studio
1.
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
proxy ExternalInterfaceProxy
(IntrovertIMApp) Shockwave Flash ActiveX
proxy_ExternalInterfaceCall() ExternalInterfaceCall
Flash Player ExternalInterfaceProxy C#
ActionScript
644
API
ExternalInterfaceCallEventArgs e
FunctionCall ExternalInterfaceCall
ExternalInterfaceCall FunctionName
ActionScript [Link]() ActionScript
ExternalInterfaceCall Arguments
switch FunctionName
([Link]) AppForm
switch
API ActiveX
645
ExternalInterfaceProxy
ActiveX
646
API
ActionScript ActionScript
Shockwave Flash ActiveX FlashCall SWF
ExternalInterfaceProxy
ExternalInterfaceProxy _flashControl_FlashCall()
API ActiveX
647
EncodeResult() XML
ExternalInterfaceCall
648
API
26
Flash Player
26
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
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
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
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
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
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>
[Link]
SWF [Link]()
[Link]
[Link] 8080 HTTPS [Link]
656
Flash Player
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>
HTTPS
false
HTTPS SWF HTTP
Adobe SWF HTTPS
HTTPS SWF
HTTP secure="false" <allow-access-from>
<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
658
Flash Player
Flash Player
[Link]()
ActionScript API [Link]()
SWF SWF [Link]
SWF
[Link]("[Link]")
SWF 668
670
671
IP [Link]() IP
URL IP
IP [Link]
IP [Link] [Link]("[Link]")
[Link]
* [Link]()
SWF SWF
*
659
[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
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]
Security.LOCAL_WITH_NETWORK SWF
Security.LOCAL_TRUSTED
SWF Internet
SWF Flash
Player SWF
Internet
API
SWF API
internal SWF API
API
none SWF API
SWF SWF API
API SecurityError
all
662
Flash Player
HTML SWF
allowNetworking Flash Adobe Flex Builder HTML
AC_FL_RunContent() SWF allowNetworking
navigateToURL()
fscommand()
[Link]()
sendToURL()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
[Link]()
API
663
[Link]()
[Link]()
[Link]()
Flash
HTML SWF
allowFullScreen Flash Flex Builder HTML
AC_FL_RunContent() SWF allowFullScreen
ActionScript
Flash Player
664
Flash Player
ActionScript
Esc
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);
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
SWF
SWF
securityDomain
SWF applicationDomain
603 ApplicationDomain
362
666
Flash Player
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>
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]()
668
Flash Player
SWF
SWF [Link] [Link] [Link]
[Link]
[Link] / [Link]
SWF
[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]()
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
<img> checkPolicyFile
667 <img> SWF
[Link]()
SWF
[Link]()
SWF
Sound id3
SWF
id3
[Link]()
[Link]()
672
Flash Player
[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
673
SWF ActionScript ActionScript
ActionScript SWF
URLLoader URLStream
XML URLLoader URLStream load()
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
676
Flash Player
Flash Player 6 Flash Player SWF
SWF [Link]
(www) Flash Player 6 [Link]
[Link] [Link] [Link]
[Link] [Link]
[Link] [Link] SWF
6 SWF
ActionScript 3.0 SWF [Link]
false [Link]()
LocalConnection
LocalConnection SWF LocalConnection
SWF SWF
SWF SWF
LocalConnection
677
[Link]() navigateToURL("javascript:
_parent
[Link]()
SWF SWF
HTML
AllowScriptAccess never
AllowScriptAccess always
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()
SharedObject SWF
SWF SWF
URL
SWF
[Link]() [Link]()
localPath
URL SWF
URL SWF '/' localPath
Flash Player
100 KB
652 654
679
SWF
HTML SWF
SWF
[Link]() [Link]() null
[Link]/products/flashplayer/articles/thirdpartylso
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
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
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
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
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
222
217
221
272
286
217
ActionScript 234
ECMAScript 232
232
229, 286
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
251
691
97
86
72
79
G
61
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
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
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
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
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
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