DisplayObject
to be shared between IGraphicElement
* objects.
*
* Group
uses ISharedDisplayObject
to manage
* invalidation and redrawing of sequences of IGraphicElement
* objects that share a DisplayObject
.
*
* Typically when implementing a custom IGraphicElement
* Developers also implement this interface for the DisplayObject
* that the custom IGraphicElement
creates.
*/
public interface ISharedDisplayObject
{
/**
* True when any of the IGraphicElement
objects, that share
* this DisplayObject
, needs to redraw. This is used internally
* by the Group
class and developers don't typically use this.
* The Group
sets and reads back this property in order to
* determine which graphic elements to validate.
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*/
function get redrawRequested():Boolean;
function set redrawRequested(value:Boolean):void;
}
}
package spark.core
{
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import spark.components.Group;
import mx.core.IVisualElement;
/**
* The IGraphicElement
is implemented by IVisualElements that
* take advantage of the parent Group's
DisplayObject
* management.
*
* One typical use case is DisplayObject
sharing.
* Group
organizes its
* IGraphicElement
children in sequences that share and draw to
* the same DisplayObject
.
* The DisplayObject
is created by the first element in the
* sequence.
Another use case is when an element does not derrive from
* DisplayObject
but instead maintains, creates and/or destroys
* its own DisplayObject
. The Group
will ensure to
* call the element to create the DisplayObject
, add the
* DisplayObject
as its child at the correct index as well as
* handle its removal.
GraphicElement
class
* instead of directly implementing the IGraphciElement
* interface as GraphicElement
already provides most of the
* required functionality.
*
*/
public interface IGraphicElement extends IVisualElement
{
//--------------------------------------------------------------------------
//
// Properties
//
//--------------------------------------------------------------------------
//----------------------------------
// displayObject
//----------------------------------
/**
* The shared DisplayObject
where this
* IGraphicElement
is drawn.
*
* Implementers should not create the DisplayObject
* here, but in createDisplayObject()
.
*
* @see #createDisplayObject
* @see #validateDisplayList
* @see #sharedIndex
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*/
function get displayObject():DisplayObject;
//----------------------------------
// sharedIndex
//----------------------------------
/**
* The index of this IGraphicElement
in the sequence
* of elements that share the same DisplayObject
.
*
* A value of -1 indicates that this element doesn't
* share its displayObject
with other elements and its sequence
* doesn't contain any other elements.
*
* A value of 0 or greater indicates the position of this element in its
* sequence.
*
* A value of 0 also indicates that this element creates the
* DisplayObject
for its sequence.
*
* Group
manages this property.
*
* @see #displayObject
* @see #createDisplayObject
*
* @langversion 3.0
* @playerversion Flash 10
* @playerversion AIR 1.5
* @productversion Flex 4
*/
function get sharedIndex():int;
/**
* @private
*/
function set sharedIndex(value:int):void;
//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------
/**
* Creates a new DisplayObject
where this IGraphicElement
* is drawn.
*
* Subsequent calls to the getter of the displayObject
property must
* return the same display object.
*
* After the DisplayObject
is created, the parent Group
* will pass along the display objects to the rest of the elements in the sequence.
*
* Group
will ensure that this method is called only when needed.
*
* If the element wants to participate in the DisplayObject
* sharing, then the new DisplayObject must implement IShareableDisplayObject
.
* This interface is being used by the Group to manage invalidation and
* redrawing of the graphic element sequence and typically is not directly
* used by the Developer.
Group
* graphicElementLayerChanged()
method.
*
* To force the Group
to remove the element's current
* DisplayObject
from its display list and recalculate the
* display object sharing, call the parent Group
* discardDisplayObject()
method.
*
* @return The display object created
* @see #displayObject
* @see spark.components.Group#graphicElementLayerChanged
* @see spark.components.Group#discardDisplayObject
*
*/
function createDisplayObject():DisplayObject;
/**
* Determines whether this element can draw itself to the
* sharedDisplayObject
of the sequence.
*
* Typically implementers will return true
when this
* IGraphicElement
can cumulatively draw in the shared
* DisplayObject
graphics
property.
* In all cases where this IGraphicElement
needs to set
* properties on the DisplayObject
that don't apply to the
* rest of the elements in the sequence this method must return false
.
* Examples for such properties are rotation, scale, transform,
* mask, alpha, filters, color transform, 3D, layer, etc.
displayObject
property must return the same display object.
*
* Note that in certain cases the sharedDisplayObject
may be
* the parent Group
itself. In the rest of the cases the
* DisplayObject
is created by the first element in the sequence.
When this IGraphicElement
needs to rebuild its sequence,
* it notifies the parent Group
by calling its
* graphicElementLayerChanged()
method.
IGraphicElement
can draw itself
* to the shared DisplayObject
of the sequence.
*
* @see #canShareWithPrevious
* @see #canShareWithNext
* @see spark.components.Group#graphicElementLayerChanged
*
*/
function setSharedDisplayObject(sharedDisplayObject:DisplayObject):Boolean;
/**
* Return true if this IGraphicElement
is compatible and can
* share display objects with the previous IGraphicElement
* in the sequence.
*
* Note that in certain cases the element may be passed offered the parent
* Group
itself in a call to setSharedDisplayObject
.
* In those cases, this method won't be called.
IGraphicElement
is compatible and can
* share display objects with the next IGraphicElement
* in the sequence.
*
* @param element The element that comes after this element in the sequence.
* @return Returns true when this element is compatible with the previous
* element in the sequence.
*
* @see #canShareWithPrevious
* @see #setSharedDisplayObject
*
*/
function canShareWithNext(element:IGraphicElement):Boolean;
/**
* Called by Group
when an IGraphicElement
* is added to or removed from a Group
.
* Developers typically never need to call this method.
*
* @param parent The parent group of this IGraphicElement
.
*
*/
function parentChanged(parent:Group):void;
/**
* Called by the parent Group
to validate the properties of
* this element.
*
* To ensure this method is called, notify the parent Group
* by calling its graphicElementPropertiesChanged()
method.
*
* Note that this method may be called even if this element have not
* notified the parent Group
.
*
* @see #validateSize
* @see #validateDisplayList
*
*/
function validateProperties():void;
/**
* Called by the parent Group
to validate the size of
* this element.
*
* When the size of the element changes and is going to affect the
* parent Group
layout, the implementer is responsible
* for invalidating the parent's size and display list.
*
* To ensure this method is called, notify the parent Group
* by calling its graphicElementSizeChanged()
method.
*
* Note that this method may be called even if this element have not
* notified the parent Group
.
*
* @see #validateProperties
* @see #validateDisplayList
*
*/
function validateSize():void;
/**
* Called by the parent Group
to redraw this element
* in its displayObject
property.
*
* If the element is the first in the sequence (sharedIndex
* is less than or equal to zero) it must clear the displayObject
* graphics and set it up as necessary for drawing the rest of the elements.
The element must alway redraw even if it itself has not changed
* since the last time validateDisplayList()
was called
* as the parent Group
will redraw the whole sequence
* if any of its elements need to be redrawn.
To ensure this method is called, notify the parent Group
* by calling its graphicElementSizeChanged()
method.
Note that this method may be called even if this element have not
* notified the parent Group
.
DisplayObject
from this Group's
* display list.
*
* The Group
also ensures any elements that share the
* DisplayObject
will be redrawn.
*
* This method doesn't necessarily trigger new DisplayObject
* reassignment for the passed in element
.
* To request new display object reassignment, call the
* graphicElementLayerChanged
method.