-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswf-spec-19.txt
More file actions
16249 lines (10204 loc) · 369 KB
/
Copy pathswf-spec-19.txt
File metadata and controls
16249 lines (10204 loc) · 369 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SWF FILE FORMAT SPECIFICATION
VERSION 19
Copyright © 2006-2012 Adobe Systems Incorporated. All rights reserved. This manual may not be copied,
photocopied, reproduced, translated, or converted to any electronic or machine-readable form in whole or in
part without written approval from Adobe Systems Incorporated. Notwithstanding the foregoing, a person
obtaining an electronic version of this manual from Adobe may print out one copy of this manual provided that
no part of this manual may be printed out, reproduced, distributed, resold, or transmitted for any other
purposes, including, without limitation, commercial purposes, such as selling copies of this documentation or
providing paid-for support services.
Trademarks
Adobe, ActionScript, Flash, Flash Media Server, Adobe Media Server, Flash Player, PostScript, and XMP are either
registered trademarks or trademarks of Adobe Systems Incorporated and may be registered in the United States
or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases
mentioned within this publication may be trademarks, service marks, or trade names of Adobe Systems
Incorporated or other entities and may be registered in certain jurisdictions including internationally. No right or
license is granted to any Adobe trademark.
Third-Party Information
This guide contains links to third-party websites that are not under the control of Adobe Systems Incorporated,
and Adobe Systems Incorporated is not responsible for the content on any linked site. If you access a third-party
website mentioned in this guide, then you do so at your own risk. Adobe Systems Incorporated provides these
links only as a convenience, and the inclusion of the link does not imply that Adobe Systems Incorporated
endorses or accepts any responsibility for the content on those third- party sites. No right, license or interest is
granted in any third party technology referenced in this guide.
NOTICE: THIS PUBLICATION AND THE INFORMATION HEREIN IS FURNISHED “AS IS”, IS SUBJECT TO CHANGE
WITHOUT NOTICE, AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY ADOBE SYSTEMS INCORPORATED.
ADOBE SYSTEMS INCORPORATED ASSUMES NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
INACCURACIES, MAKES NO WARRANTY OF ANY KIND (EXPRESS, IMPLIED, OR STATUTORY) WITH RESPECT TO
THIS PUBLICATION, AND EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES OF MERCHANTABILITY, FITNESS FOR
PARTICULAR PURPOSES, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
Adobe Systems Incorporated - Published 2012
Contents
Introduction ............................................................................................................................................................. 12
Chapter 1: Basic Data Types .................................................................................................................................... 14
Coordinates and twips ......................................................................................................................................... 14
Integer types and byte order............................................................................................................................... 14
Fixed-point numbers ........................................................................................................................................... 15
Floating-point numbers ....................................................................................................................................... 16
Encoded integers ................................................................................................................................................. 16
Bit values ............................................................................................................................................................. 17
Using bit values.................................................................................................................................................... 18
String values ........................................................................................................................................................ 19
Language code ..................................................................................................................................................... 20
RGB color record ................................................................................................................................................. 21
RGBA color with alpha record ............................................................................................................................. 21
ARGB color with alpha record ............................................................................................................................. 21
Rectangle record ................................................................................................................................................. 22
MATRIX record..................................................................................................................................................... 22
Color transform record........................................................................................................................................ 24
Color transform with alpha record ...................................................................................................................... 25
Chapter 2: SWF Structure Summary ................................................................................................................. 27
The SWF header .................................................................................................................................................. 27
SWF file structure ................................................................................................................................................ 28
Tag format ........................................................................................................................................................... 29
Definition and control tags .................................................................................................................................. 29
Tag ordering in SWF files ..................................................................................................................................... 30
The dictionary ...................................................................................................................................................... 30
Processing a SWF file ........................................................................................................................................... 32
File compression strategy.................................................................................................................................... 32
Summary.............................................................................................................................................................. 32
Chapter 3: The Display List ...................................................................................................................................... 33
Clipping layers ..................................................................................................................................................... 33
Using the display list ............................................................................................................................................ 33
Display list tags .................................................................................................................................................... 34
PlaceObject ...................................................................................................................................................... 34
PlaceObject2 .................................................................................................................................................... 35
PlaceObject3 .................................................................................................................................................... 38
Color Matrix filter ............................................................................................................................................ 42
Convolution filter............................................................................................................................................. 42
Blur filter .......................................................................................................................................................... 44
Drop Shadow filter........................................................................................................................................... 45
Glow filter ........................................................................................................................................................ 46
Bevel filter ....................................................................................................................................................... 46
Gradient Glow and Gradient Bevel filters ....................................................................................................... 47
ClipEventFlags .................................................................................................................................................. 48
RemoveObject ................................................................................................................................................. 50
RemoveObject2 ............................................................................................................................................... 50
ShowFrame ...................................................................................................................................................... 51
Chapter 4: Control Tags ........................................................................................................................................... 52
SetBackgroundColor ............................................................................................................................................ 52
FrameLabel .......................................................................................................................................................... 52
Protect ................................................................................................................................................................. 53
End ....................................................................................................................................................................... 53
ExportAssets ........................................................................................................................................................ 53
ImportAssets........................................................................................................................................................ 54
EnableDebugger .................................................................................................................................................. 55
EnableDebugger2 ................................................................................................................................................ 55
ScriptLimits .......................................................................................................................................................... 56
SetTabIndex ......................................................................................................................................................... 56
FileAttributes ....................................................................................................................................................... 57
ImportAssets2...................................................................................................................................................... 58
SymbolClass ......................................................................................................................................................... 59
Metadata ............................................................................................................................................................. 59
DefineScalingGrid ................................................................................................................................................ 60
DefineSceneAndFrameLabelData ........................................................................................................................ 62
Chapter 5: Actions ................................................................................................................................................... 63
SWF 3 action model ............................................................................................................................................. 63
SWF 3 actions .................................................................................................................................................. 64
SWF 4 action model ............................................................................................................................................. 67
The program counter....................................................................................................................................... 68
SWF 4 actions .................................................................................................................................................. 68
SWF 5 action model ............................................................................................................................................. 89
SWF 5 actions .................................................................................................................................................. 89
ScriptObject actions......................................................................................................................................... 90
Type actions ................................................................................................................................................... 100
Math actions .................................................................................................................................................. 102
Stack operator actions ................................................................................................................................... 103
SWF 6 action model ........................................................................................................................................... 108
SWF 6 actions ................................................................................................................................................ 108
SWF 7 action model ........................................................................................................................................... 111
SWF 7 actions ................................................................................................................................................ 111
SWF 9 action model ........................................................................................................................................... 117
DoABC ............................................................................................................................................................ 117
SWF 10 action model ......................................................................................................................................... 118
Chapter 6: Shapes.................................................................................................................................................. 119
Shape overview ................................................................................................................................................. 119
Shape example .................................................................................................................................................. 120
Shape structures ................................................................................................................................................ 121
Fill styles ........................................................................................................................................................ 121
Line styles ...................................................................................................................................................... 123
Shape structures ............................................................................................................................................ 125
Shape tags...................................................................................................................................................... 131
Chapter 7: Gradients ............................................................................................................................................. 134
Gradient transformations .................................................................................................................................. 134
Gradient control points ..................................................................................................................................... 135
Gradient structures ........................................................................................................................................... 135
GRADIENT ...................................................................................................................................................... 135
FOCALGRADIENT............................................................................................................................................ 136
GRADRECORD ................................................................................................................................................ 136
Chapter 8: Bitmaps ................................................................................................................................................ 137
DefineBits .......................................................................................................................................................... 137
JPEGTables ......................................................................................................................................................... 137
DefineBitsJPEG2................................................................................................................................................. 138
DefineBitsJPEG3................................................................................................................................................. 139
DefineBitsLossless ............................................................................................................................................. 139
DefineBitsLossless2 ........................................................................................................................................... 142
DefineBitsJPEG4................................................................................................................................................. 143
Chapter 9: Shape Morphing .................................................................................................................................. 144
DefineMorphShape ........................................................................................................................................... 145
DefineMorphShape2 ......................................................................................................................................... 146
Morph fill styles ................................................................................................................................................. 148
MORPHFILLSTYLEARRAY ................................................................................................................................ 148
MORPHFILLSTYLE ........................................................................................................................................... 148
Morph gradient values ...................................................................................................................................... 149
MORPHGRADIENT ......................................................................................................................................... 149
MORPHGRADRECORD ................................................................................................................................... 149
Morph line styles ............................................................................................................................................... 150
MORPHLINESTYLEARRAY ............................................................................................................................... 150
MORPHLINESTYLE .......................................................................................................................................... 150
MORPHLINESTYLE2 ........................................................................................................................................ 150
Chapter 10: Fonts and Text ................................................................................................................................... 152
Glyph text and device text................................................................................................................................. 152
Static text and dynamic text .............................................................................................................................. 152
Glyph text .......................................................................................................................................................... 153
Glyph definitions ........................................................................................................................................... 153
The EM square ............................................................................................................................................... 154
Converting TrueType fonts to SWF glyphs .................................................................................................... 154
Kerning and advance values .......................................................................................................................... 155
Advanced text rendering engine ................................................................................................................... 155
DefineFont and DefineText ........................................................................................................................... 156
Static glyph text example .............................................................................................................................. 157
Font tags ............................................................................................................................................................ 158
DefineFont ..................................................................................................................................................... 158
DefineFontInfo............................................................................................................................................... 158
Western indirect fonts................................................................................................................................... 160
Japanese indirect fonts .................................................................................................................................. 160
DefineFontInfo2............................................................................................................................................. 161
DefineFont2 ................................................................................................................................................... 162
DefineFont3 ................................................................................................................................................... 164
DefineFontAlignZones ................................................................................................................................... 166
Kerning record ............................................................................................................................................... 167
DefineFontName ........................................................................................................................................... 168
Static text tags ................................................................................................................................................... 168
DefineText ..................................................................................................................................................... 168
Text records ................................................................................................................................................... 169
Dynamic text tags .............................................................................................................................................. 171
DefineEditText ............................................................................................................................................... 171
CSMTextSettings ............................................................................................................................................ 174
DefineFont4 ................................................................................................................................................... 175
Chapter 11: Sounds ............................................................................................................................................... 177
Audio coding formats ........................................................................................................................................ 177
Event sounds ..................................................................................................................................................... 178
DefineSound .................................................................................................................................................. 178
StartSound ..................................................................................................................................................... 179
StartSound2 ................................................................................................................................................... 180
Sound styles ................................................................................................................................................... 180
Streaming sound................................................................................................................................................ 181
SoundStreamHead......................................................................................................................................... 181
SoundStreamHead2....................................................................................................................................... 183
SoundStreamBlock ........................................................................................................................................ 184
Frame subdivision for streaming sound ........................................................................................................ 184
ADPCM compression ......................................................................................................................................... 186
ADPCM sound data........................................................................................................................................ 187
MP3 compression .............................................................................................................................................. 188
MP3 sound data............................................................................................................................................. 188
MP3 frame ..................................................................................................................................................... 190
Nellymoser compression ................................................................................................................................... 192
Speex compression ............................................................................................................................................ 192
Chapter 12: Buttons .............................................................................................................................................. 193
Button states ..................................................................................................................................................... 193
Button tracking .................................................................................................................................................. 193
Events, state transitions, and actions................................................................................................................ 194
Button tags ...................................................................................................................................................... 195
Buttonrecord ................................................................................................................................................. 195
DefineButton ................................................................................................................................................. 196
DefineButton2 ............................................................................................................................................... 197
DefineButtonCxform ..................................................................................................................................... 199
DefineButtonSound ....................................................................................................................................... 199
Chapter 13: Sprites and Movie Clips ..................................................................................................................... 201
Sprite names ...................................................................................................................................................... 201
DefineSprite ....................................................................................................................................................... 202
Chapter 14: Video .................................................................................................................................................. 204
Sorenson H.263 Bitstream Format .................................................................................................................... 204
Summary of differences from H.263 ............................................................................................................. 204
Video packet .................................................................................................................................................. 205
Macro block ................................................................................................................................................... 206
Block data ...................................................................................................................................................... 207
Screen Video bitstream format ......................................................................................................................... 208
Block format .................................................................................................................................................. 208
Video packet .................................................................................................................................................. 209
Image block.................................................................................................................................................... 210
Screen Video V2 bitstream format .................................................................................................................... 210
V2 Colorspace ................................................................................................................................................ 210
V2 Video Packet ............................................................................................................................................. 211
Image Block V2 .............................................................................................................................................. 212
Image format ................................................................................................................................................. 212
Image block diff position ............................................................................................................................... 213
Image block prime position ........................................................................................................................... 213
On2 Truemotion VP6 bitstream format ............................................................................................................ 213
VP6 FLV video packet .................................................................................................................................... 215
VP6 FLV Alpha video packet .......................................................................................................................... 215
VP6 SWF video packet ................................................................................................................................... 216
VP6 SWF Alpha video packet ......................................................................................................................... 216
SWF video tags .................................................................................................................................................. 216
DefineVideoStream ....................................................................................................................................... 217
VideoFrame ................................................................................................................................................... 217
Chapter 15: Metadata........................................................................................................................................... 219
FileAttributes ..................................................................................................................................................... 219
EnableTelemetry ............................................................................................................................................... 220
DefineBinaryData .............................................................................................................................................. 220
Appendix A: SWF Uncovered: A Simple SWF File Dissected ................................................................................. 221
Appendix B: Reverse index of tag values............................................................................................................... 235
Appendix C: Screen Video v2 Palette .................................................................................................................... 238
Introduction
The SWF (pronounced “swiff ”) file format delivers vector graphics, text, video, and sound over the Internet and
is supported by Adobe® Flash® Player software. The SWF file format is designed to be an efficient delivery
format, not a format for exchanging graphics between graphics editors. It is designed to meet the following
goals:
•
On-screen display—The format is primarily intended for on-screen display and supports anti-aliasing,
fast rendering to a bitmap of any color format, animation, and interactive buttons.
•
Extensibility—The format is a tagged format, so it can be evolved with new features while maintaining
backward compatibility with earlier versions of Flash Player.
•
Network delivery—The format can travel over a network with limited and unpredictable bandwidth. The
files are compressed to be small and support incremental rendering through streaming. The SWF file
format is a binary format and is not human readable like HTML. The SWF file format uses techniques
such as bit-packing and structures with optional fields to minimize file size.
•
Simplicity—The format is simple so that Flash Player is small and easily ported. Also, Flash Player
depends upon a limited set of operating system features only.
•
File independence—The files display with minimal dependence on external resources such as fonts.
•
Scalability—The files work well on limited hardware, and can take advantage of better hardware when it
is available. This ability is important because computers have different monitor resolutions and bit
depths.
•
Speed—The graphics described by SWF files render quickly.
•
Scriptability—The format includes tags that provide sequences of byte codes to be interpreted by a
stack machine. The byte codes support the ActionScript® language. Flash Player provides a runtime
ActionScript object model that allows interaction with drawing primitives, servers, and features of Flash
Player.
SWF files have the extension .swf and a MIME type of application/x-shockwave-flash.
The SWF format has evolved through several versions. Through SWF 5, substantial additions were made to the
SWF tag set. Starting with SWF 6 and later, the SWF format changes less, as more new features are implemented
partly or entirely at the ActionScript level. Starting with SWF 9, the ActionScript 3.0 language, which employs the
new ActionScript Virtual Machine 2 (AVM2) can be used. Anyone planning to generate SWF file content that
uses newer features should become familiar with the ActionScript object model that Flash Player exposes. Some
references for this information are in the ActionScript Developer's Guide (see
http://help.adobe.com/en_US/as3/dev/index.html), ActionScript 3.0 Language Reference (see
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/), and the Adobe ActionScript Virtual
12
Machine 2 Overview (PDF file) at www.adobe.com/go/avm2overview.
If you need to knows the mapping between Flash Player / AIR names to SWF version (for example, 11.4 is SWF
17), look up the features in a given release, or check out the latest in what’s new in the Flash Player and SWF
features, visit: Flash Player and Air Feature List.
Adobe seriously considers all feedback to the SWF file format specification. E-mail any unclear or potentially
erroneous information within the specification to Adobe at flashformat@adobe.com. All such email submissions
shall be subject to the Submitted Materials guidelines in the Terms of Use at
www.adobe.com/misc/copyright.html.
Summary of post-ship changes:
•
13
April 23, 2013 – Fixed wrong order in ActionStackSwap
Chapter 1: Basic Data Types
This section describes the basic data types that make up the more complex data structures in the SWF file
format. All other structures in the SWF file format are built on these fundamental types.
Coordinates and twips
The SWF file format stores all x-y coordinates as integers, usually in a unit of measurement called a twip. In the
SWF format, a twip is 1/20th of a logical pixel. A logical pixel is the same as a screen pixel when the file is played
at 100%—that is, without scaling.
For example, a rectangle 800 twips wide by 400 twips high is rendered as 40 by 20 logical pixels. Fractional pixel
sizes are approximated with anti-aliasing. A rectangle 790 by 390 twips (39.5 by 19.5 pixels) appears to have
slightly blurred edges.
Twips are a good compromise between size and precision. They provide sub-pixel accuracy for zooming and
precise placement of objects, while consuming very few bits per coordinate.
Coordinates in the SWF file format use the traditional graphics axes: x is horizontal and proceeds from minimum
values at the left to maximum values at the right, and y is vertical and proceeds from minimum values at the top
to maximum values at the bottom.
Integer types and byte order
The SWF file format uses 8-bit, 16-bit, 32-bit, 64-bit, signed, and unsigned integer types. All integer values are
stored in the SWF file by using little-endian byte order: the least significant byte is stored first, and the most
significant byte is stored last, in the same way as the Intel x86 architecture. The bit order within bytes in the
SWF file format is big-endian: the most significant bit is stored first, and the least significant bit is stored last.
For example:
•
•
The 32-bit value 0x456e7120 is stored as 20 71
The 16-bit value 0xe712 is stored as 12 e7.
6e 45.
All integer types must be byte-aligned. That is, the first bit of an integer value must be stored in the first bit of a
byte in the SWF file.
Signed integers are represented by using traditional 2’s-complement bit patterns. These are the signed integer
representations used on most modern computer platforms. In the 2’s complement system, negative numbers
have 1 as the first bit, and zero and positive numbers have 0 as the first bit. A negative number, -n, is
represented as the bitwise opposite of the positive-zero number n-1.
14
Integer Types
Type
Comment
SI8
Signed 8-bit integer value
SI16
Signed 16-bit integer value
SI32
Signed 32-bit integer value
SI8[n]
Signed 8-bit array—n is the number of array elements
SI16[n]
Signed 16-bit array—n is the is number of array elements
UI8
Unsigned 8-bit integer value
UI16
Unsigned 16-bit integer value
UI32
Unsigned 32-bit integer value
UI8[n]
Unsigned 8-bit array—n is the number of array elements
UI16[n]
Unsigned 16-bit array—n is the number of array elements
UI24[n]
Unsigned 24-bit array—n is the number of array elements
UI32[n]
Unsigned 32-bit array—n is the number of array elements
UI64[n]
Unsigned 64-bit array—n is the number of array elements
Fixed-point numbers
The SWF file format supports two types of fixed-point numbers: 32-bit and 16-bit.
The 32-bit fixed-point numbers are 16.16. That is, the high 16 bits represent the number before the decimal
point, and the low 16 bits represent the number after the decimal point. FIXED values are stored like 32-bit
integers in the SWF file (using little-endian byte order) and must be byte aligned.
For example: The real value 7.5 is equivalent to: 0x0007.8000. This value is stored in the SWF file as: 00 80 07
00.
SWF 8 and later supports 16-bit 8.8 signed, fixed-point numbers. The high 8 bits represent the number before
the decimal point, and the low 8 bits represent the number after the decimal point. FIXED8 values are stored like
16-bit integers in the SWF file (using little- endian byte order) and must be byte aligned.
15
Fixed-Point Types
Type
Comment
FIXED
32-bit 16.16 fixed-point number
FIXED8
16-bit 8.8 fixed-point number
Floating-point numbers
SWF 8 and later supports the use of IEEE Standard 754 compatible floating-point types. Three types of floatingpoint numbers are supported.
Floating-Point Types
Type
Comment
FLOAT16
Half-precision (16-bit) floating-point number
FLOAT
Single-precision (32-bit) IEEE Standard 754 compatible
DOUBLE
Double-precision (64-bit) IEEE Standard 754 compatible
FLOAT16 is identical to the characteristics of FLOAT except for changes to the number of bits allocated to the
exponent and mantissa:
•
•
•
1 bit for the sign
5 bits for the exponent, with an exponent bias of 16
10 bits for the mantissa
Encoded integers
SWF 9 and later supports the use of integers encoded with a variable number of bytes. One type of encoded
integer is supported.
Floating-Point Types
Type
Comment
EncodedU32
Variable length encoded 32-bit unsigned integer
This is a 32-bit unsigned integer value encoded with a variable number of bytes to save space. All EncodedU32's
are encoded as 1-5 bytes depending on the value (larger values need more space). The encoding method is if the
hi bit in the current byte is set, then the next byte is also part of the value. Each bit in a byte contributes 7 bits to
the value, with the hi bit telling us whether to use the next byte, or if this is the last byte for the value.
16
This is the algorithm for parsing an EncodedU32:
int GetEncodedU32(unsigned char*& pos)
{
int result = pos[0];
if (!(result & 0x00000080))
{
pos++;
return result;
}
result = (result & 0x0000007f) | pos[1]<<7;
if (!(result & 0x00004000))
{
pos += 2;
return result;
}
result = (result & 0x00003fff) | pos[2]<<14;
if (!(result & 0x00200000))
{
pos += 3;
return result;
}
result = (result & 0x001fffff) | pos[3]<<21;
if (!(result & 0x10000000))
{
pos += 4;
return result;
}
result = (result & 0x0fffffff) | pos[4]<<28;
pos += 5;
return result;
}
Bit values
Bit values are variable-length bit fields that can represent three types of numbers:
1. Unsigned integers
2. Signed integers
3. Signed 16.16 fixed-point values.
Bit values do not have to be byte aligned. Other types (such as UI8 and UI16) are always byte aligned. If a bytealigned type follows a bit value, the last byte that contains the bit value is padded with zeros.
The following example is a stream of 64 bits. The 64 bits represent 9 values of varying bit length, followed by a
UI16 value:
The bit stream begins with a 6-bit value (BV1), followed by a 5-bit value (BV2) that is spread across Byte1 and
17
Byte2. BV3 is spread across Byte2 and Byte3, while BV4 is wholly contained within Byte3. Byte 5 contains two bit
values: BV7 and BV8. BV9 is followed by a byte- aligned type (UI16), so the last four bits of Byte 6 are padded
with zeros.
Bit Values
Type
Comment
SB[nBits]
Signed-bit value (nBits is the number of bits used to store the value)
UB[nBits]
Unsigned-bit value (nBits is the number of bits used to store the value)
FB[nBits]
Signed, fixed-point bit value (nBits is the number of bits used to store the value)
When an unsigned-bit value is expanded into a larger word size, the leftmost bits are filled with zeros. When a
signed-bit value is expanded into a larger word size, the high bit is copied to the leftmost bits.
This expansion is called sign extension. For example, the 4-bit unsigned value UB[4] = 1110 would be expanded
to a 16-bit value like this: 0000000000001110 = 14. The same value interpreted as a signed value, SB[4] = 1110
would be expanded to 1111111111111110 = –2.
Signed-bit values are similar but must take account of the sign bit. The signed value of 35 is represented as SB[7]
= 0100011. The extra zero bit is required; otherwise the high bit is sign extended and the value is interpreted as
negative.
Fixed-point bit values are 32-bit 16.16 signed, fixed-point numbers. That is, the high 16 bits represent the
number before the decimal point, and the low 16 bits represent the number after the decimal point. A fixedpoint bit value is identical to a signed-bit value, but the interpretation is different. For example, a 19-bit, signedbit value of 0x30000 is interpreted as
196608 decimal. The 19-bit, fixed-point bit value 0x30000 is interpreted as 3.0. The format of this value is
effectively 3.16 rather than 16.16.
Using bit values
Bit values are stored by using the minimum number of bits possible for the range needed. Most bit value fields
use a fixed number of bits. Some use a variable number of bits, but in all such cases, the number of bits to be
used is explicitly stated in another field in the same structure. In these variable-length cases, applications that
generate SWF files must determine the minimum number of bits necessary to represent the actual values that
will be specified. For signed-bit values, if the number to be encoded is positive, an extra bit is necessary to
preserve the leading 0; otherwise sign extension changes the bit value into a negative number.
18
As an example of variable-sized bit values, consider the RECT structure:
Field
Type
Comment
Nbits
UB[5]
Bits in each rect value field
Xmin
SB[Nbits]
x minimum position for rect
Xmax
SB[Nbits]
x maximum position for rect
Ymin
SB[Nbits]
y minimum position for rect
Ymax
SB[Nbits]
y maximum position for rect
The Nbits field determines the number of bits used to store the coordinate values Xmin, Xmax, Ymin, and Ymax.
Say the coordinates of the rectangle are as follows:
Xmin = 127
Xmax = 260
Ymin = 15
Ymax = 514
decimal = 1111111 binary
decimal = 100000100 binary
decimal = 1111 binary
decimal = 1000000010 binary
Nbits is calculated by finding the coordinate that requires the most bits to represent. In this case, that value is
514 (01000000010 binary) which requires 11 bits to represent. The rectangle is stored as the following table
shows:
Field
Type and Value
Comment
Nbits
UB[5] = 01011
Bits required (11)
Xmin
SB[11] = 00100000100
x minimum in twips (127)
Xmax
SB[11] = 00001111111
x maximum in twips (260)
Ymin
SB[11] = 00000001111
y minimum in twips (15)
Ymax
SB[11] = 01000000010
y maximum in twips (514)
String values
A string value represents a null-terminated character string. The format for a string value is a sequential list of
bytes terminated by the null character byte.
Field
Type
Comment
String
UI8[zero or more]
Non-null string character data
19
StringEnd
UI8
Marks end of string; always zero
In SWF 5 or earlier, STRING values are encoded using either ANSI (which is a superset of ASCII) or shift-JIS (a
Japanese encoding). You cannot indicate the encoding that is used; instead, the decoding choice is made
according to the locale in which Flash Player is running. This means that text content in SWF 5 or earlier can only
be encoded in ANSI or shift-JIS, and the target audience must be known during authoring—otherwise garbled
text results.
In SWF 6 or later, STRING values are always encoded by using the Unicode UTF-8 standard. This is a multibyte
encoding; each character is composed of between one and four bytes. UTF-8 is a superset of ASCII; the byte
range 0 to 127 in UTF-8 exactly matches the ASCII mapping, and all ASCII characters 0 to 127 are represented by
just one byte. UTF-8 guarantees that whenever a character other than character 0 (the null character) is
encoded by using more than one byte, none of those bytes are zero. This avoids the appearance of internal null
characters in UTF-8 strings, meaning that it remains safe to treat null bytes as string terminators, just as for ASCII
strings.
Language code
A language code identifies a spoken language that applies to text. Language codes are associated with font
specifications in the SWF file format.
Note: A language code does not specify a text encoding; it specifies a spoken language.
Field
Type
Comment
LanguageCode
UI8
Language code (see following)
Flash Player uses language codes to determine line-breaking rules for dynamic text, and to choose backup fonts
when a specified device font is unavailable. Other uses for language codes may be found in the future.
A language code of zero means no language. This code results in behavior that is dependent on the locale in
which Flash Player is running.
At the time of writing, the following language codes are recognized by Flash Player:
20
•
1 = Latin (the western languages covered by Latin-1: English, French, German, and so on)
•
2 = Japanese
•
3 = Korean
•
4 = Simplified Chinese
•
5 = Traditional Chinese
RGB color record
The RGB record represents a color as a 24-bit red, green, and blue value.
Field
Type
Comment
Red
UI8
Red color value
Green
UI8
Green color value
Blue
UI8
Blue color value
RGBA color with alpha record
The RGBA record represents a color as 32-bit red, green, blue and alpha value. An RGBA color with an alpha
value of 255 is completely opaque. An RGBA color with an alpha value of zero is completely transparent. Alpha
values between zero and 255 are partially transparent.
Field
Type
Comment
Red
UI8
Red color value
Green
UI8
Green color value
Blue
UI8
Blue color value
Alpha
UI8
alpha value defining opacity
ARGB color with alpha record
The ARGB record behaves exactly like the RGBA record, but the alpha value for the ARGB record is in the first
byte.
Field
Type
Comment
Alpha
UI8
alpha value defining opacity
Red
UI8
Red color value
Green
UI8
Green color value
Blue
UI8
Blue color value
21
Rectangle record
A rectangle value represents a rectangular region defined by a minimum x- and y-coordinate position and a
maximum x- and y-coordinate position. The RECT record must be byte aligned.
Field
Type
Comment
Nbits
UB[5]
Bits used for each subsequent field
Xmin
SB[Nbits]
x minimum position for rectangle in twips
Xmax
SB[Nbits]
x maximum position for rectangle in twips
Ymin
SB[Nbits]
y minimum position for rectangle in twips
Ymax
SB[Nbits]
y maximum position for rectangle in twips
MATRIX record
The MATRIX record represents a standard 2x3 transformation matrix of the sort commonly used in 2D graphics.
It is used to describe the scale, rotation, and translation of a graphic object. The MATRIX record must be byte
aligned.
Field
Type
Comment
HasScale
UB[1]
Has scale values if equal to 1
NScaleBits
If HasScale = 1, UB[5]
Bits in each scale value field
ScaleX
If HasScale = 1, FB[NScaleBits]
x scale value
ScaleY
If HasScale = 1, FB[NScaleBits]
y scale value
HasRotate
UB[1]
Has rotate and skew values if equal to 1
NRotateBits
If HasRotate = 1, UB[5]
Bits in each rotate value field
RotateSkew0
If HasRotate = 1, FB[NRotateBits]
First rotate and skew value
RotateSkew1
If HasRotate = 1, FB[NRotateBits]
Second rotate and skew value
NTranslateBits
UB[5]
Bits in each translate value field
TranslateX
SB[NTranslateBits]
x translate value in twips
TranslateY
SB[NTranslateBits]
y translate value in twips
22
The ScaleX, ScaleY, RotateSkew0 and RotateSkew1 fields are stored as 16.16 fixed-point values. The TranslateX
and TranslateY values are stored as signed values in twips.
The MATRIX record is optimized for common cases such as a matrix that performs a translation only. In this case,
the HasScale and HasRotate flags are zero, and the matrix only contains the TranslateX and TranslateY fields.
The mapping from the MATRIX fields to the 2x3 matrix is as follows:
ScaleX
RotateSkew0
RotateSkew1
ScaleY
TranslateX
TranslateY
For any coordinates (x, y), the transformed coordinates (x', y') are calculated as follows:
x' = x * ScaleX + y * RotateSkew1 + TranslateX
y' = x * RotateSkew0 + y * ScaleY + TranslateY
The following table describes how the members of the matrix are used for each type of operation:
ScaleX
RotateSkew0
RotateSkew1
ScaleY
Rotation
Cosine
Sine