NAME
SWF::Element - Classes of SWF tags and elements.
SYNOPSIS
use SWF::Element;
use SWF::BinStream;
$swf_stream=SWF::BinStream::Write;
....
$rect=SWF::Element::RECT->new;
$rect->configure(Xmin=>0, Ymin=>0, Xmax=>100, Ymax=>100);
$rect->pack($swf_stream);
....
DESCRIPTION
SWF::Element module handles SWF tags and any other sub elements to create, configure, clone, pack to bit strings, and unpack from bit strings.
SWF::Element::*
SWF::Element class is a base class of SWF element, such as Tag, RECT, SHAPE, etc. Each SWF::Element object has one or more fields. Each field is also SWF::Element object.
METHODS
- $element=SWF::Element::* ->new([parameters]);
-
creates a new element. The new element is configured with parameters.
- $element->clone;
-
duplicates the element.
- $element->configure( [name[=>value, ...]] );
-
gets and sets fields of the element.
When calling without any parameter, the method returns all field names and values of the element as hash.
When calling with a field name, the method returns the field value of the element.
When calling with one or more pair of name and value, the method sets the field of the element and returns the element itself. If value is an array reference, recursively configure the field element.
- $element->defined;
-
returns whether $element is defined or not. The $element is NOT defined if all of its field are not defined.
- $element->dumper([\&outputsub, $indent]);
-
dumps the element as a perl script which can re-create the element.
- $element->pack($stream);
-
writes the element to $stream as bit string SWF format. $stream should be SWF::BinStream::Write object.
- $element->unpack($stream);
-
reads the bit string data from $stream and unpack the element. $stream should be SWF::BinStream::Read object.
- $element->FieldName([configure parameters...]);
-
Each field of $element can access by field name. When calling without parameter, it returns the field object. when calling with the same element object or the configure parameters of the field, it sets the field with the parameters and returns the field object.
- $element->FlagName([value]);
-
The element has some flag accessor if the element has the field which consists some flags. When calling without value, it returns the flag value. When calilng with the value, it sets proper bit(s) of the Flags field with the value and returns the flag value.
SWF::Element::Scalar and its derivatives
SWF::Element::Scalar and its derivatives represent a field whose value is a scalar. SWF::Element::Scalar doesn't have pack/unpack methods, so the parent element is responsible to pack/unpack it. There are some derivative classes which has pack/unpack methods:
SWF::Element::UI8/16/32 - 8/16/32 bits unsigned integer.
SWF::Element::SI8/16/32 - 8/16/32 bits signed integer.
SWF::Element::STRING - null-terminated string.
SWF::Element::PSTRING - pascal type string (string with its length).
SWF::Element::ID - 16bit ID of SWF shapes, bipmaps, sounds, etc.
SWF::Element::BinData - Binary Data (described later).
When the object of these classes is used in expression, it is degraded to mere scalar.
# to be transparent
$new_alpha = $color->Alpha / 2;
$color->Alpha($new_alpha);
or
$color->Alpha($color->Alpha / 2);
When you want to get a field value into a variable, it is recommended to use value method, or it may cause an unexpect change of the field.
#$alpha = $color->Alpha; # NOT recommended.
$alpha = $color->Alpha->value;
METHODS
SWF::Element::Scalar has all methods of SWF::Element except any field/flag accessors. Here described the difference.
- $scalar->configure([value])
-
gets and sets the object. When calling without any parameter, the method returns the value of the object. When calling with a value, the method sets the value to the object and returns the value.
- $scalar->value
-
returns the value of the object.
SWF::Element::BinData
represents a binary data.
METHODS
It has the same methods as SWF::Element::Scalar. The other methods are described here.
- $bindata->Length
-
returns the length of the data.
- $bindata->add( string )
-
adds a string to the data.
- $bindata->substr( offset [, length , [replace]] )
-
Extracts a substring out of the data. It behaves similar to CORE::substr.
- $bindata->save( file )
-
saves the data to the file. It takes a file name or a file handle.
- $bindata->load( file )
-
loads the data from the file. It takes a file name or a file handle.
SWF::Element::Array::*
SWF::Element::Array is a base class which represents an array of the SWF element. The SWF::Element::Array object is an array reference.
METHODS
SWF::Element::Array has all methods of SWF::Element except any field/flag accessors. Here described the difference.
- $array->configure( list... )
-
adds list to the array. Each element of the list must be a proper element object or an array reference.
- $array->new_element
-
creates a proper new element for the array. The new element is not add the array automatically. You should do 'push @$array, $new' if you want to add the new element.
SUBCLASSES
Here is the list of all subclasses representing the SWF element. 'SWF::Element::' is omitted from each class name. ex. RECT means SWF::Element::RECT class. See 'SWF file reference' for further information about SWF elements and fields. You can download the document from http://openswf.org/ .
Basic Types
- RGB / RGBA
-
represents a color without/with alpha channel.
field class Red UI8 Green UI8 Blue UI8 Alpha UI8 - RGBA only
- RECT
-
represents a rectanglular region.
field class Xmin Scalar Ymin Scalar Xmax Scalar Ymax Scalar
- MATRIX
-
represents a matrix for scale, rotation, and translation.
field class ScaleX Scalar ScaleY Scalar RotateSkew0 Scalar RotateSkew1 Scalar TranslateX Scalar TranslateY Scalar
There are three methods.
- CXFORM / CXFORMWITHALPHA
-
represents a color transform value.
field class RedMultTerm Scalar GreenMultTerm Scalar BlueMultTerm Scalar AlphaMultTerm Scalar - CXFORMWITHALPHA only. RedAddTerm Scalar GreenAddTerm Scalar BlueAddTerm Scalar AlphaAddTerm Scalar - CXFORMWITHALPHA only.
SWF Tags
- Tag
-
A base class of all SWF tags.
- Tag::Unidentified
-
is an empty tag object. When it is unpacked from SWF stream, it is re-blessed the proper tag class.
- Tag::Undefined
-
represents the undefined tags.
field class Data BinData
Shapes
- Array::FILLSTYLEARRAY1 / 2 / 3
-
An array of fill styles. FILLSTYLEARRAY1 and 2 have FILLSTYLE1, and FILLSTYLEARRAY3 has FILLSTYLE3.
- FILLSTYLE1 / 3
-
represents fill style of shapes. FILLSTYLE3 has alpha channels in its field elements.
field class FillStyleType UI8 Color RGB / RGBA GradientMatrix MATRIX Gradient Array::GRADIENT1 / 3 BitmapID ID BitmapMatrix MATRIX
- Array::GRADIENT1 / 3
-
represents a gradient information. Each of them is an array of GRADRECORD1 / 3.
- GRADRECORD1 / 3
-
represents one of the colors making gradient. GRADRECORD3 has an alpha channel.
field class Ratio UI8 Color RGB / RGBA
- Array::LINESTYLEARRAY1 / 2 / 3
-
An array of line styles. LINESTYLEARRAY1 and 2 have LINESTYLE1, and LINESTYLEARRAY3 has LINESTYLE3.
- LINESTYLE1 / 3
-
represents a line style of shapes. LINESTYLE3 has an alpha channel.
field class Width UI16 Color RGB / RGBA
- SHAPE1 / 2 / 3
-
represents a shape without styles. SHAPE3 has alpha channels.
field class ShapeRecords Array::SHAPERECARRAY1 / 2 / 3
- SHAPEWITHSTYLE1 / 2 / 3
-
represents a shape with styles. SHAPEWITHSTYLE3 has alpha channels.
field class FillStyles Array::FILLSTYLEARRAY1 / 2 / 3 LineStyles Array::LINESTYLEARRAY1 / 2 / 3 ShapeRecords Array::SHAPERECARRAY1 / 2 / 3
- Array::SHAPERECARRAY1 / 2 / 3
-
An array of SHAPEREC1 / 2 / 3.
- SHAPEREC1 / 2 / 3
-
is a base class of the edges of a shape. If you configure this element, the element is re-blessed with proper subclass.
- SHAPEREC1/2/3::NEWSHAPE
-
represents a start point and style of new edge.
field class MoveX Scalar MoveY Scalar Fill0Style Scalar Fill1Style Scalar LineStyle Scalar FillStyles Array::FILLSTYLEARRAY1 / 2 / 3 LineStyles Array::LINESTYLEARRAY1 / 2 / 3
- SHAPERECn::STRAIGHTEDGE
-
represents an straight edge. This is common subclass of SHAPEREC1/2/3.
field class X Scalar Y Scalar
- SHAPERECn::CURVEDEDGE
-
represents an curved edge. This is common subclass of SHAPEREC1/2/3.
field class ControlX Scalar ControlY Scalar AnchorX Scalar AnchorY Scalar
- Tag::DefineShape / Tag::DefineShape2 / Tag::DefineShape3
-
defines shape. DefineShape2/3 can have more than 255 styles. DefineShape3 contains alpha channels.
field class ShapeID ID ShapeBounds RECT Shapes SHAPEWITHSTYLE1 / 2 / 3
- Tag::DefineMorphShape
-
defines the metamorphosis of one shape (Shape1) into another (Shape2).
field class CharacterID ID ShapeBounds1 RECT ShapeBounds2 RECT MorphFillStyles Array::MORPHFILLSTYLEARRAY MorphLineStyles Array::MORPHLINESTYLEARRAY Edges1 SHAPE3 Edges2 SHAPE3
- Array::MORPHFILLSTYLEARRAY
-
An array of MORPHFILLSTYLE.
- MORPHFILLSTYLE
-
represents fill styles for DefineMorphShape tag.
field class FillStyleType UI8 Color1 RGBA Color2 RGBA GradientMatrix1 MATRIX GradientMatrix2 MATRIX Gradient Array::MORPHGRADIENT BitmapID ID BitmapMatrix1 MATRIX BitmapMatrix2 MATRIX
- Array::MORPHGRADIENT
-
An array of MORPHGRADRECORD.
- MORPHGRADRECORD
-
represents one of the colors making gradient for DefineMorphShape.
field class Ratio1 UI8 Color1 RGBA Ratio2 UI8 Color2 RGBA
- Array::MORPHLINESTYLEARRAY
-
An array of MORPHLINESTYLE.
- MORPHLINESTYLE
-
represents a line style of shapes for DefineMorphShape.
field class Width1 UI16 Color1 RGBA Width2 UI16 Color2 RGBA
Bitmaps
- Tag::DefineBits
-
defines JPEG image data.
field class BitmapID ID BitmapJPEGImage BinData
- Tag::DefineBitsJPEG2 / 3
-
defines JPEG image data and an encoding table. DefineBitsJPEG3 has an alpha data table.
field class BitmapID ID BitmapJPEGEncoding BinData BitmapJPEGImage BinData BitmapAlphaData BinData - JPEG3 only.
- Tag::DefineBitsLossless / Tag::DefineBitsLossless2
-
defines a loss-less bitmap. DefineBitsLossless2 contains alpha channels.
field class BitmapID ID BitmapFormat UI8 BitmapWidth UI16 BitmapHeight UI16 BitmapColorTableSize UI8 CompressedData BinData
- Tag::JPEGTable
-
defines JPEG encoding table.
field class BitmapJPEGEncoding BinData
Buttons
-
defines a button character.
field class ButtonID ID Buttons Array::BUTTONRECORDARRAY1 Actions Array::ACTIONRECORDARRAY
- Tag::DefineButton2
-
defines a button character.
field class ButtonID ID Flags UI8 Buttons Array::BUTTONRECORDARRAY2 Button2ActionCondition Array::ACTIONCONDITIONARRAY
- Array::BUTTONRECORDARRAY1 / 2
-
An array of BUTTONRECORD1 / 2.
- BUTTONRECORD1 / 2
-
represents a button character and associated button states.
field class ButtonStates UI8 StateHitTest (ButtonStates) StateDown (ButtonStates) StateUp (ButtonStates) StateOver (ButtonStates) ButtonCharacter UI16 ButtonLayer UI16 ButtonMatrix MATRIX ColorTransform CXFORMWITHALPHA - only BUTTONRECORD2
- Array::ACTIONCONDITIONARRAY
-
An array of ACTIONCONDITION.
- ACTIONCONDITION
-
represents actions and a button states condition which triggers off the actions.
field class Condition UI16 IdleToOverUp (Condition) OverUpToIdle (Condition) OverUpToOverDown (Condition) OverDownToOverUp (Condition) OverDownToOutDown (Condition) OutDownToOverDown (Condition) OutDownToIdle (Condition) IdleToOverDown (Condition) OverDownToIdle (Condition) Actions Array::ACTIONRECORDARRAY
- Tag::DefineButtonCxform
-
defines the color transform for each shape and text character in a button.
field class ButtonID ID ButtonColorTransform CXFORM
- Tag::DefineButtonSound
-
defines the sound data for a button.
field class ButtonID ID ButtonSoundChar0 ID ButtonSoundInfo0 SOUNDINFO ButtonSoundChar1 ID ButtonSoundInfo1 SOUNDINFO ButtonSoundChar2 ID ButtonSoundInfo2 SOUNDINFO ButtonSoundChar3 ID ButtonSoundInfo3 SOUNDINFO
Fonts and Text
- Tag::DefineFont
-
defines font glyphs.
field class FontID ID ShapeTable SHAPEARRAY1
- Array::SHAPEARRAY1 / 2
-
An array of SHAPE1 / 2.
- Tag::DefineFont2
-
defines font glyphs and other information.
field class FontID ID FontFlags UI16 FontFlagsBold (FontFlags) FontFlagsItalic (FontFlags) FontFlagsANSI (FontFlags) FontFlagsUnicode (FontFlags) FontFlagsShiftJIS (FontFlags) FontName PSTRING FontShapeTable Array::SHAPEARRAY2 FontCodeTable Array::FONTCODETABLE FontAscent SI16 FontDescent SI16 FontLeading SI16 FontAdvanceTable Array::FONTADVANCETABLE FontBoundsTable Array::FONTBOUNDSTABLE FontKerningTable FONTKERNINGTABLE
- Array::FONTCODETABLE / FONTADVANCETABLE / FONTBOUNDSTABLE
-
are arrays of a code, an advance value, and a bounding box of each glyph corresponding to the shape table, respectively. A code and an advance value are scalar, and a bounding box is a RECT.
- FONTKERNINGTABLE
-
represents a table of kerning pairs of the font. Each kerning pair is described as 'code1-code2'. For example, a pair of 'T'(code 84) and 'o'(111) is '84-111'.
- $kern->configure([ pair [=> adjustment, ...]])
-
When calling without any parameter, it returns all kerning pair and its adjustment. When calling with a kerning pair, it returns the adjustment of the pair. When calling with the list of a kerning pair and its adjustment, it adds the kerning data to the table.
- Tag::DefineFontInfo
-
defines font information.
field class FontID ID FontName PSTRING FontFlags UI8 FontFlagsBold (FontFlags) FontFlagsItalic (FontFlags) FontFlagsANSI (FontFlags) FontFlagsUnicode (FontFlags) FontFlagsShiftJIS (FontFlags) FontCodeTable Array::FONTCODETABLE
- Tag::DefineText / Tag::DefineText2
-
defines text.
field class TextID ID TextBounds RECT TextMatrix MATRIX TextRecords Array::TEXTRECORDARRAY1 / 2
- Array::TEXTRECORDARRAY1 / 2
-
An array of TEXTRECORD1 / 2
- TEXTRECORD1 / 2
-
A base class of text records. If you configure this element, the element is re-blessed with proper subclass.
- TEXTRECORD::Type0
-
represents a text string.
field class GlyphEntries Array:GLYPHENTRYARRAY
- Array::GLYPHENTRYARRAY
-
An array of GLYPHENTRY.
- GLYPHENTRY
-
represents a glyph entry for a letter of the text.
field class TextGlyphIndex Scalar TextGlyphAdvance Scalar
- TEXTRECORD1/2::Type1
-
represents a text style.
field class TextFont ID TextColor RGB / RGBA TextXOffset SI16 TextYOffset SI16 TextHeight UI16
- Tag::DefineEditText
-
defines an edit box.
field class TextFieldID ID TextFieldBounds RECT Flags UI16 FlagReadOnly (Flags) FlagPassword (Flags) FlagMultiline (Flags) FlagWordWrap (Flags) FlagUseOutlines (Flags) FontID ID FontHeight UI16 TextColor RGBA MaxLength UI16 Align UI8 LeftMargin UI16 RightMargin UI16 Indent UI16 Leading UI16 Variable STRING InitialText STRING
Sounds
- SOUNDINFO
-
represents sound information.
field class SyncFlags Scalar InPoint UI32 OutPoint UI32 LoopCount UI16 EnvelopeRecords Array::SNDENVARRAY
- Array::SNDENVARRAY
-
An array of SNDENV.
- SNDENV
-
represents sound envelope information.
field class Mark44 UI32 Level0 UI16 Level1 UI16
- Tag::DefineSound
-
defines sound.
field class SoundID ID Flags UI8 SoundFormat (Flags) SoundRate (Flags) SoundSize (Flags) SoundType (Flags) SoundSampleCount UI32 SoundData BinData
- Tag::SoundStreamBlock
-
defines streaming sound.
field class StreamsoundData BinData
- Tag::SoundStreamHead / Tag::SoundStreamHead2
-
defines the start of streaming sound.
field class StreamSoundMixFormat UI8 Flags UI8 SoundFormat (Flags) SoundRate (Flags) SoundSize (Flags) SoundType (Flags) StreamSoundSampleCount UI16
Sprites
- Tag::DefineSprite
-
defines a sprite.
field class SpriteID ID FrameCount UI6 MiniFileStructure Bindata
Display List
- Tag::PlaceObject
-
places the object.
field class CharacterID ID Depth UI16 Matrix MATRIX ColorTransform CXFORM
- Tag::PlaceObject2
-
places the object.
field class Flags UI8 HasMove (Flags) Depth UI16 CharacterID ID Matrix MATRIX ColorTramsform CXFORMWITHALPHA Ratio UI16 ClipDepth UI16 Name STRING EventActions Array::EVENTACTIONARRAY
- Array::EVENTACTIONARRAY
-
An array of EVENTACTION.
- EVENTACTION
-
represents an event and frame actions triggered by it.
field class Flags UI16 OnLoad (Flags) EnterFrame (Flags) Unload (Flags) MouseMove (Flags) MouseDown (Flags) MouseUp (Flags) KeyDown (Flags) KeyUp (Flags) Data (Flags) Action Array::ACTIONBLOCK2
- Tag::RemoveObject / Tag::RemoveObject2
-
removes the object.
field class CharacterID ID - RemoveObject only Depth UI16
- Tag::ShowFrame
-
shows current frame.
Controls
- Tag::BackgroundColor
-
sets the background color.
field class BackgroundColor RGB
- Tag::FrameLabel
-
sets the frame label.
field class Label STRING
- Tag::FreeCharacter
-
frees the character.
field class CharacterID ID
- Tag::NameCharacter
-
names the character.
field class CharacterID ID Name STRING
- Tag::Protect
-
prevents the file from editing in the authoring tool.
field class Password BinData
- Tag::StartSound
-
starts playing sound.
field class SoundID ID SoundInfo SOUNDINFO
- Tag::End
-
marks the end of the file.
- Tag::ExportAssets
-
field class Assets Array::ASSETARRAY
- Tag::ImportAssets
-
field class Assets Array::ASSETARRAY
- Array::ASSETARRAY
-
An array of ASSET.
- ASSET
-
field class ID UI16 String STRING
Actions
- Tag::DoAction
-
performs the action.
field class Actions Array::ACTIONRECORDARRAY
- Array::ACTIONRECORDARRAY
-
An array of ACTIONRECORD
- ACTIONRECORD
-
represents action tags without any parameter.
field class Tag ACTIONTagNumber
- ACTIONTagNumber
-
represents an action tag number or name.
- ACTIONRECORD::ActionUndefined
-
represents an undefined actiontag.
field class Tag ACTIONTagNumber Data BinData
- ACTIONRECORD::ActionGotoFrame
-
goes to the specified frame.
field class Tag ACTIONTagNumber Frame UI16
- ACTIONRECORD::ActionGetURL
-
directs the player to get the specified URL.
field class Tag ACTIONTagNumber URLString STRING WinString STRING
- ACTIONRECORD::ActionWaitForFrame
-
waits until the specified frame otherwise skip the specified number of actions.
field class Tag ACTIONTagNumber Frame UI16 SkipCount UI8
- ACTIONRECORD::ActionSetTarget
-
sets context of action.
field class Tag ACTIONTagNumber TargetName STRING
- ACTIONRECORD::ActionGotoLabel
-
goes to frame associated with the specified label.
field class Tag ACTIONTagNumber Label STRING
- ACTIONRECORD::WaitForFrame2
-
waits until the frame specified in the stack otherwise skip the specified number of actions.
field class Tag ACTIONTagNumber SkipCount UI8
- ACTIONRECORD::PushData
-
pushes data to the stack.
field class Tag ACTIONTagNumber DataList Array::ACTIONDATAARRAY
- Array::ACTIONDATAARRAY
-
An array of ACTIONDATA
- ACTIONDATA
-
A base class of data for action script. If you configure this element, the element is re-blessed with proper subclass.
- ACTIONRECORD::BranchAlways / BranchIfTrue
-
branches action script always / if stack top is true.
field class Offset UI16
- ACTIONRECORD::GetURL2
-
directs the player to get the URL specified in the stack.
field class Tag ACTIONTagNumber Method UI8
- ACTIONRECORD::ActionGotoFrame2
-
goes to the frame specified in the stack.
field class Tag ACTIONTagNumber Flag UI8
- ACTIORECORD::ActionDefineDictionary
-
defines word set which can be referred by index.
field class Tag ActionTagNumber Words Array::WORDARRAY
- Array::WORDARRAY
-
an array of STRING.
- ACTIONRECORD::ActionDefineFunction
-
defines a function.
field class Tag ActionTagNumber Name STRING Args Array::ACTIONFUNCARGS Function Array::ACTIONBLOCK
- Array::ACTIONFUNCARGS
-
An array of STRING.
- Array::ACTIONBLOCK / Array::ACTIONBLOCK2
-
an array of ACTIONRECORD.
- ACTIONRECORD::ActionStoreRegister
-
stores the stack top to the register.
field class Tag ActionTagNumber Register UI8
- ACTIONRECORD::ActionWith
-
refers to the object on the top of stack for the member and the method written in the WithBlock, like 'With' statement of Visual Basic.
field class WithBlock Array::ACTIONBLOCK
COPYRIGHT
Copyright 2000 Yasuhiro Sasama (ySas), <ysas@nmt.ne.jp>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
SWF file format and SWF file reference in SWF SDK.