Packageflash.text.engine
Classpublic final class GraphicElement
InheritanceGraphicElement Inheritance ContentElement Inheritance Object

Language Version : ActionScript 3.0
Player Version : Flash Player 10

The GraphicElement class represents a graphic element in a TextBlock or GroupElement object. Assign a GraphicElement object to the content property of a TextBlock object to display a graphic or an image with TextBlock.createTextLine(), Assign it to a GroupElement object to combine it with other graphic and text elements.

See also

TextBlock
ContentElement


Public Properties
 PropertyDefined By
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
 InheritedelementFormat : ElementFormat
The ElementFormat used for the element.
ContentElement
  elementHeight : Number
The height in pixels to reserve for the graphic in the line.
GraphicElement
  elementWidth : Number
The width in pixels to reserve for the graphic in the line.
GraphicElement
 InheritedeventMirror : EventDispatcher
The EventDispatcher object that receives copies of every event dispatched to text lines based on this content element.
ContentElement
  graphic : DisplayObject
The DisplayObject to be used as a graphic for the GraphicElement.
GraphicElement
 InheritedgroupElement : GroupElement
[read-only] The GroupElement which contains this element, or null if it is not in a group.
ContentElement
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
 InheritedrawText : String
[read-only] A copy of the text in the element, including the U+FDEF characters representing graphic elements.
ContentElement
 Inheritedtext : String
[read-only] A copy of the text in the element, not including the U+FDEF characters representing graphic elements.
ContentElement
 InheritedtextBlock : TextBlock
[read-only] The TextBlock to which this element belongs.
ContentElement
 InheritedtextBlockBeginIndex : int
[read-only] The index in the text block of the first character of this element.
ContentElement
 InheritedtextRotation : String
The rotation to apply to the element as a unit.
ContentElement
 InheriteduserData : *
Provides a way for the author to associate arbitrary data with the element.
ContentElement
Public Methods
 MethodDefined By
  
GraphicElement(graphic:DisplayObject = null, elementWidth:Number = 15.0, elementHeight:Number = 15.0, elementFormat:ElementFormat = null, eventMirror:EventDispatcher = null, textRotation:String = "rotate0")
Creates a new GraphicElement instance.
GraphicElement
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Public Constants
 ConstantDefined By
 InheritedGRAPHIC_ELEMENT : uint = 0xFDEF
[static] Used to indicate the presence a graphic element in the text.
ContentElement
Property Detail
elementHeightproperty
elementHeight:Number  [read-write]

Language Version : ActionScript 3.0
Player Version : Flash Player 10

The height in pixels to reserve for the graphic in the line. It is the responsibility of the caller to scale the graphic.

The default value is 15.0.


Implementation
    public function get elementHeight():Number
    public function set elementHeight(value:Number):void

Throws
ArgumentError — the value is less than this.elementHeight.
elementWidthproperty 
elementWidth:Number  [read-write]

Language Version : ActionScript 3.0
Player Version : Flash Player 10

The width in pixels to reserve for the graphic in the line. It is the responsibility of the caller to scale the graphic.

The default value is 15.0.


Implementation
    public function get elementWidth():Number
    public function set elementWidth(value:Number):void

Throws
ArgumentError — the value is less than this.elementWidth.
graphicproperty 
graphic:DisplayObject  [read-write]

Language Version : ActionScript 3.0
Player Version : Flash Player 9

The DisplayObject to be used as a graphic for the GraphicElement.

The default value is null.

When the GraphicElement becomes part of a text line, the graphic is added as a child of the line. Setting the graphic will remove the old graphic from the line and add the new one.


Implementation
    public function get graphic():DisplayObject
    public function set graphic(value:DisplayObject):void

Throws
ArgumentError — the registration point of graphic is not at the top left.
 
ArgumentError — the graphic.width is greater than this.elementWidth or graphic.height is greater than this.elementHeight.
Constructor Detail
GraphicElement()Constructor
public function GraphicElement(graphic:DisplayObject = null, elementWidth:Number = 15.0, elementHeight:Number = 15.0, elementFormat:ElementFormat = null, eventMirror:EventDispatcher = null, textRotation:String = "rotate0")

Language Version : ActionScript 3.0
Player Version : Flash Player 10

Creates a new GraphicElement instance.

The registration point of the graphic aligns with the top left corner of the region defined by elementHeight, elementWidth and elementFormat.baselineShift. The registration point of the graphic must be at the top left corner of the graphic. The graphic will not be scaled to match the size of the region.

Parameters
graphic:DisplayObject (default = null) — The DisplayObject to populate the GraphicElement. The default value is null.
 
elementWidth:Number (default = 15.0) — The width of the area reserved for the element in pixels. The default value is 15.
 
elementHeight:Number (default = 15.0) — The height of the area reserved for the element in pixels. The default value is 15.
 
elementFormat:ElementFormat (default = null) — The element format for the element. The default value is null.
 
eventMirror:EventDispatcher (default = null) — The EventDispatcher object that receives copies of every event dispatched to text lines created based on this content element. The default value is null.
 
textRotation:String (default = "rotate0") — The rotation applied the element as a unit. Use flash.text.engine.TextRotation constants for this property. The default value is flash.text.engine.TextRotation.ROTATE_0.

Throws
ArgumentError — the registration point of graphic is not at the top left (0, 0).
 
ArgumentError — the graphic.width is greater than elementWidth or graphic.height is greater than elementHeight.

Example

The following example creates a TextBlock with a GraphicElement (a red box) and displays it, adding a second TextBlock beneath it that contains a caption.

package {

    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.text.engine.TextBlock;
    import flash.text.engine.TextElement;
    import flash.text.engine.GraphicElement;
    import flash.text.engine.TextLine;
    import flash.text.engine.ElementFormat;
    import flash.text.engine.FontDescription;
    
    public class GraphicElementExample extends Sprite {
        
        public function GraphicElementExample():void {
            var format:ElementFormat = new ElementFormat();
            format.fontSize = 14;
            var redBox:MovieClip = new MovieClip();
            redBox.graphics.beginFill(0xCC0000, 1.0);
            redBox.graphics.drawRect(0,0, 200, 200);
            redBox.graphics.endFill();   
            var graphicElement:GraphicElement = new GraphicElement(redBox,redBox.width,redBox.height, format);
            var textBlock:TextBlock = new TextBlock();
            textBlock.content = graphicElement;
            var textLine1:TextLine = textBlock.createTextLine(null,redBox.width);
            addChild(textLine1);
            textLine1.x = 15
            textLine1.y = 215
            var str:String = "Your picture here ...";
            var textElement:TextElement = new TextElement(str, format);
            textBlock = new TextBlock();
            textBlock.content = textElement;
            var textLine2 = textBlock.createTextLine(null, 300);
            addChild(textLine2);
            textLine2.x = textLine1.x;
            textLine2.y += textLine1.y + format.fontSize;        
        }
    }    
}