You can add effects such as masks, alpha, and blend modes
to graphic elements and groups.
Flash Player renders graphic elements and effects on those elements
in the following order:
GraphicElement or Group
Alpha
Masks
Filters
Blend modes
Masks in FXG and MXML graphics
You can add masks to any instance group element. A mask
defines the region in which the group’s content is rendered. There
are two kinds of masking: clipping and alpha.
In clip masking, only the actual path, shapes, and fills
defined by the mask are used to determine the effect on the source
content. Strokes and bitmap filters on the mask are ignored. Filled
regions in the mask are considered filled, and Flash Player renders
the source content. The type of fill is not relevant: solid color, gradient
fill, or bitmap fills in a mask all render the underlying source
content, regardless of the alpha values of the mask fill.
In alpha masking, the opacity of each pixel in the source
content is multiplied by the opacity of the corresponding region
of the mask.
To specify a mask, you add a mask as a child of a group or graphic
element. A mask must contain a single child tag, either a Group
instance or a locally-defined tag from the library. The mask defines
its child to be the clipping mask for its parent.
You set the type of masking to use with the maskType property
on the mask’s parent graphical element. You can set the value of
this property to either alpha or clip.
In FXG, if the <mask> tag is a child of
the root tag, then it must be the first tag. If there is a <Library> tag,
then it must be the second tag.
FXG example
The following example uses FXG components to define masks:
The executing SWF file for the previous example is shown below:
Filters in FXG and MXML graphics
A filter effect consists of a series of graphic operations
applied to the rendered graphic of a grouping element and its children
before compositing it into the background.
Filters can only be defined on shapes and group instances, not
group definitions. That means they can be defined on a Group tag
placed as an immediate child of a Graphic or other Group tag, or
as a child of a library object that references a defined group.
To define a filter in FXG, add the <filters> child
tag to the Group or shape you want to apply the filter to. To define
a filter in MXML graphics, you add a <s:filters> tag
to the Group or shape you want to apply the filter to. The filters
are defined in the spark.filters package.
The FXG <filters> child tag and the <s:filters> MXML
tag must contain one or more of the bitmap filter types.
Flash Player applies filters to the rendered content of the tag
in the order that they appear in the document: the first filter
modifies the rendered content, the second filter modifies the output
of the first filter, and so on.
The following table lists the filters that are supported by FXG
and MXML graphics. It also lists the FXG attributes and children.
For the supported properties of the MXML graphics equivalents, see
the ActionScript 3.0 Reference for the Adobe
Flash Platform.
FXG tag
Equivalent MXML graphics tag and ActionScript
class
MXML graphics also support an AnimateFilter effect, that lets
you animate a filter at runtime. Unlike effects that animate properties
of the target, the AnimateFilter effect animates properties of the
filter applied to the target. For more information, see Spark filter effects.
In some cases, you can use the RectangularDropShadow class
to apply a drop shadow to a graphic element, rather than using the
DropShadowFilter effect. It is more efficient, but limited in some
ways.
FXG examples
The following FXG-based example applies a drop shadow filter
to a rectangle:
The executing SWF file for the previous example is shown below:
Blend modes in FXG and MXML graphics
Graphical elements can control how their content is composited
with the background by specifying a blendMode attribute.
A grouping element with the blendMode property
set to normal acts only as a transformation on
the elements contained within. Its 2D transform, color transform,
and opacity are multiplied down into its child elements, where they
are combined with any local values to render the child element into
the current surface.
In FXG, you specify a blend mode by setting the value of the blendMode attribute
on the <Group> or graphic element (like <Rect>).
In MXML graphics, you specify a blend mode by setting the value
of the blendMode attribute on the <s:Group> tag
or graphic tag (like <s:Rect>). The possible
values are defined by the flash.display.BlendMode class.
The following table describes the available blend modes in FXG:
Blend mode
Description
add
Adds the values of the constituent colors
of the element to the colors of its background, applying a ceiling
of 0xFF.
alpha
Applies the alpha value of each pixel of
the element to the background.
auto
For grouping elements, acts the same as
setting the blend mode to normal when the alpha
of the group is 0 or 1, and the blend mode is layer when
the alpha of the group is strictly between 0 and 1. For shape elements,
acts the same as setting the blend mode to normal.
color
Creates a resulting color with the luminance
of the base color and the hue and saturation of the blend color.
This preserves the gray levels in the artwork and is useful for
coloring monochrome artwork and for tinting color artwork.
colordodge
Brightens the base color to reflect the
blend color. Blending with black produces no change.
colorburn
Darkens the base color to reflect the blend
color. Blending with white produces no change.
darken
Selects the darker of the constituent colors
of the element and the colors of the background (the colors with
the smaller values).
difference
Compares the constituent colors of the element
with the colors of its background, and subtracts the darker of the values
of the two constituent colors from the lighter value.
erase
Erases the background based on the alpha
value of the element.
exclusion
Creates an effect similar to but lower in
contrast than the Difference mode. Blending with white inverts the
base-color components. Blending with black produces no change.
hardlight
Adjusts the color of each pixel based on
the darkness of the element. If the element is lighter than 50%
gray, the element and background colors are screened, which results
in a lighter color. If the element is darker than 50% gray, the colors
are multiplied, which results in a darker color. This setting is
commonly used for shading effects.
hue
Creates a resulting color with the luminance
and saturation of the base color and the hue of the blend color.
invert
Inverts the background.
layer
The element content is pre-composed in a
temporary buffer before it is processed further.
lighten
Selects the lighter of the constituent colors
of the element and the color of the background (the colors with
the larger values).
luminosity
Creates a resulting color with the hue and
saturation of the base color and the luminance of the blend color.
This mode creates an inverse effect from that of the Color mode.
multiply
Multiplies the values of the element's constituent
colors by the colors of the background color, and then normalizes by
dividing by 0xFF, resulting in darker colors.
normal
The element content appears in front of
the background. Pixel values of the element override those of the
background. Where the element is transparent, the background is
visible.
overlay
Adjusts the color of each pixel based on
the darkness of the background. If the background is lighter than
50% gray, the element and background colors are screened, which
results in a lighter color. If the background is darker than 50%
gray, the colors are multiplied, which results in a darker color.
saturation
Creates a resulting color with the luminance
and hue of the base color and the saturation of the blend color.
Painting with this mode in an area with no saturation (gray) causes
no change.
screen
Multiplies the complement (inverse) of the
display object color by the complement of the background color,
resulting in a bleaching effect. This setting is commonly used for
highlights or to remove black areas of the display object.
softlight
Darkens or lightens the colors, depending
on the blend color. The effect is similar to shining a diffused
spotlight on the artwork.If the blend color (light source) is lighter
than 50% gray, the artwork is lightened, as if it were dodged. If the
blend color is darker than 50% gray, the artwork is darkened, as
if it were burned in. Painting with pure black or white produces
a distinctly darker or lighter area but does not result in pure
black or white.
subtract
Subtracts the values of the constituent
colors in the element from the values of the background color, applying
a floor of 0.
Color transformations are a high performance way to modify
the color of a group or shape element. A color transform can be
used, for example, to tint a group, adjust its brightness, or modify
its opacity.
Color transforms are applied to the rendering of a group or shape
element after any bitmap filters are applied; color transforms affect
the output of a filter (such as tinting the drop shadow).
They are applied before the group element is composited with its
background. Blend modes use the transformed color value when combining
the group with the background content.
In FXG, you specify a color transformation by adding a <transform> tag
as a child tag of a group. The <transform> tag
must have a single child tag <Transform>.
The <Transform> tag can have a child tag <colorTransform>.
The <colorTransform> tag must have a single
child tag <ColorTransform>. The supported
attributes of the <ColorTransform> tag are
shown in Graphics classes and elements.
Transformations are considered instanced group properties, and
can only be defined on shape elements and Groups whose parent tag
is another grouping element, or on instances of symbols. Specifically,
transformations cannot be defined on Groups whose parent tag is
a <Definition> tag, or on the topmost <Graphic> tag
of an FXG document.
Transformations can be defined on an element in one of two ways:
through discrete transform attributes, or through a child Transformation
and Matrix element. It is illegal to specify both a child element
matrix transformation and one or more transform attributes on the
same Group instance.
Discrete transforms can be specified with the attributes x,y, scaleX, scaleY, and rotation.
These attributes are combined to create a 2D transform matrix to
define the Group’s coordinate space as follows:
Scale
by scaleX, scaleY
Rotate by rotation
Translate by x, y
For more information about using color transformations in FXG,
see the FXG 2.0 specification.