7. SWF Anatomy
The structure of a SWF
SWF Header
Signature
Version
File length
Frame size
Frame rate
Frame count
Tag
Tag
Tag
Tag
Sunday, 25. April 2010
8. SWF Anatomy
The structure of a SWF
SWF Header
Signature Signature:
Version
File length ”FWS” - uncompressed
Frame size ”CWS” - compressed
Frame rate
Frame count btw... “FWS” is “SWF” backwards
Tag
Tag
Tag
Tag
Sunday, 25. April 2010
9. SWF Anatomy
The structure of a SWF
SWF Header
Signature
Version
File length
Frame size
Frame rate
Frame count
For SWF 8 or later,
FileAttributes the first tag must be
the FileAttributes tag
Tag
Tag
The last tag must be
End the End tag
Sunday, 25. April 2010
10. SWF Anatomy
The structure of a SWF
SWF Header
Signature
Version
File length
Frame size
Frame rate
Frame count
Tag
Unknown Tag
Tag
Tag
Sunday, 25. April 2010
11. SWF Anatomy
The structure of a tag
Tag Header
Type
Length
Tag Content
Sunday, 25. April 2010
12. SWF Anatomy
The structure of a tag
Tag Header
Type
Length
Tag Content
When the Flash Player encounters a tag
with an unknown type, it skips it
Extensible
Forward compatible
Sunday, 25. April 2010
13. SWF Anatomy
Data types used by SWF
A tag’s content is made up of various data types.
The exact format for each tag is defined in the SWF spec.
Some of the data types are rather obscure:
Integers Numbers Bit arrays Others
UI8 FIXED UB[nBits] String
UI16 FIXED8 SB[nBits] RGB
UI24 FLOAT FB[nBits] RGBA
UI32 FLOAT16 RECT
SI8 DOUBLE MATRIX
SI16
SI32
EncodedU32
Sunday, 25. April 2010
14. SWF Anatomy
Data types used by SWF
Example: RECT and bit arrays
01010 0000000000 1000100110 0000000000 0110010000
nBits xmin xmax ymin ymax
10 0 550 0 400
nBits specifies the minimum number of bits needed
to represent all values in the array
All values are stored as a bit stream
(no byte boundaries)
Sunday, 25. April 2010
15. SWF Anatomy
Data types used by SWF
Example: RECT and bit arrays
xmin 0 0
xmax 550 1000100110
ymin 0 0
ymax 400 110010000
Sunday, 25. April 2010
16. SWF Anatomy
Data types used by SWF
Example: RECT and bit arrays
xmin 0 0
xmax 550 1000100110
ymin 0 0
ymax 400 110010000
1110110110 nBits = 10
Sunday, 25. April 2010
17. SWF Anatomy
Data types used by SWF
Example: RECT and bit arrays
xmin 0 0000000000
xmax 550 1000100110
ymin 0 0000000000
ymax 400 0110010000
1110110110 nBits = 10
Sunday, 25. April 2010
18. SWF Anatomy
Data types used by SWF
Example: RECT and bit arrays
xmin 0 0000000000
xmax 550 1000100110
ymin 0 0000000000
ymax 400 0110010000
concatenate
0000000000 1000100110 0000000000 0110010000
Sunday, 25. April 2010
19. SWF Anatomy
Data types used by SWF
Example: RECT and bit arrays
xmin 0 0000000000
xmax 550 1000100110
ymin 0 0000000000
uses 40 + 5 bits
ymax 400 0110010000
vs 128 bits
01010 0000000000 1000100110 0000000000 0110010000
Sunday, 25. April 2010
20. SWF Anatomy
Data types used by SWF
Example: RECT and bit arrays
xmin 0 0
xmax 0 0
ymin 0 0
Special case:
uses 0 + 5 bits
ymax 0 0
vs 128 bits
00000 - - - -
Sunday, 25. April 2010
32. SWF Tag Families
Definition tags
define the SWF’s content
assign a unique character id
characters are stored in dictionary for use/reuse
DefineShape
DefineButton
DefineSprite
DefineBits
DefineFont
DefineText
DefineSound
DefineVideoStream
Sunday, 25. April 2010
33. SWF Tag Families
Control tags
control the flow of the SWF
create/manipulate instances of objects from the dictionary
PlaceObject
RemoveObject
ShowFrame
Sunday, 25. April 2010
34. The Flow
A simple example
SWF Dictionary Display list
DefineShape Empty Empty
ID 1
DefineSprite
ID 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 1
ShowFrame
Sunday, 25. April 2010
35. The Flow
A simple example
SWF Dictionary Display list
DefineShape Shape Empty
ID 1 ID 1
DefineSprite
ID 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 1
ShowFrame
Sunday, 25. April 2010
36. The Flow
A simple example
SWF Dictionary Display list
DefineShape Shape Empty
ID 1 ID 1
DefineSprite Sprite
ID 2 ID 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 1
ShowFrame
Sunday, 25. April 2010
37. The Flow
A simple example
SWF Dictionary Display list
DefineShape Shape Shape
ID 1 ID 1 at depth 1
DefineSprite Sprite
ID 2 ID 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 1
ShowFrame
Sunday, 25. April 2010
38. The Flow
A simple example
SWF Dictionary Display list
DefineShape Shape Shape
ID 1 ID 1 at depth 1
DefineSprite Sprite Sprite
ID 2 ID 2 at depth 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 1
ShowFrame
Sunday, 25. April 2010
39. The Flow
A simple example
SWF Dictionary Display list
DefineShape Shape Shape
ID 1 ID 1 at depth 1
DefineSprite Sprite Sprite
ID 2 ID 2 at depth 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 1
ShowFrame
Sunday, 25. April 2010
40. The Flow
A simple example
SWF Dictionary Display list
DefineShape Shape Shape
ID 1 ID 1 at depth 1
DefineSprite Sprite Sprite
ID 2 ID 2 at depth 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 2
ShowFrame
Sunday, 25. April 2010
41. The Flow
A simple example
SWF Dictionary Display list
DefineShape Shape Shape
ID 1 ID 1 at depth 1
DefineSprite Sprite
ID 2 ID 2
PlaceObject
ID 1 at depth 1
PlaceObject
ID 2 at depth 2
ShowFrame
RemoveObject
from depth 2
ShowFrame
Sunday, 25. April 2010
42. The FileAttributes tag
Defines some characteristics of the SWF file
[69:FileAttributes]
AS3: true
HasMetadata: true
UseDirectBlit: false
UseGPU: false
UseNetwork: true
Sunday, 25. April 2010
43. The ScriptLimits tag
Defines some characteristics of the SWF file
[65:ScriptLimits]
MaxRecursionDepth: 1000
ScriptTimeoutSeconds: 60
Sunday, 25. April 2010
44. The ProductInfo tag
Compile time/date, info about compiler used
[41:ProductInfo]
ProductID: 3
Edition: 6
Version: 4.0.0.14159
CompileDate: Wed Apr 21 03:23:16 GMT-0400 2010
ProductID (UI32)
0: Unknown
1: Macromedia Flex for J2EE
2: Macromedia Flex for .NET
3: Adobe Flex
Edition (UI32)
0: Developer Edition
1: Full Commercial Edition
2: Non Commercial Edition
3: Educational Edition
4: Not For Resale (NFR) Edition
5: Trial Edition
6: None
Sunday, 25. April 2010
45. The DefineShape tag
Defines styles and geometry of a shape
[83:DefineShape4] ID: 1, ShapeBounds: 15,125,15,125, EdgeBounds: 20,120,20,120
FillStyles:
[1] [SWFFillStyle] Type: 0 (solid), Color: FF0000
LineStyles:
[1] [SWFLineStyle2] Width: 10, Color: 000000
ShapeRecords:
[SWFShapeRecordStyleChange] MoveTo: 120,20, FillStyle1: 1, LineStyle: 1
[SWFShapeRecordStraightEdge] Vertical: 100
[SWFShapeRecordStraightEdge] Horizontal: -100
[SWFShapeRecordStraightEdge] Vertical: -100
[SWFShapeRecordStraightEdge] Horizontal: 100
[SWFShapeRecordEnd]
Sunday, 25. April 2010
46. The DefineShape tag
Defines styles and geometry of a shape
[83:DefineShape4] ID: 1, ShapeBounds: 15,125,15,125, EdgeBounds: 20,120,20,120
FillStyles:
[1] [SWFFillStyle] Type: 0 (solid), Color: FF0000
LineStyles:
[1] [SWFLineStyle2] Width: 10, Color: 000000
ShapeRecords:
[SWFShapeRecordStyleChange] MoveTo: 120,20, FillStyle1: 1, LineStyle: 1
[SWFShapeRecordStraightEdge] Vertical: 100
[SWFShapeRecordStraightEdge] Horizontal: -100
[SWFShapeRecordStraightEdge] Vertical: -100
[SWFShapeRecordStraightEdge] Horizontal: 100
[SWFShapeRecordEnd]
Shape records are NOT drawing
instructions!
They merely DEFINE the styles and
geometry of the shape!
Sunday, 25. April 2010