Adobe® Flex® 4 Language Reference
Show Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
flash.text.engine 
GraphicElement 
Packageflash.text.engine
Classpublic final class GraphicElement
InheritanceGraphicElement Inheritance ContentElement Inheritance Object

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5, Flash Lite 4

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.

View the examples

See also



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 object 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 valid 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 object that 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 any U+FDEF characters.
ContentElement
 Inheritedtext : String
[read-only] A copy of the text in the element, not including any U+FDEF characters, which represent graphic elements in the String.
ContentElement
 InheritedtextBlock : flash.text.engine: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 an application 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 this object, formatted according to locale-specific conventions.
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] Indicates the presence of a graphic element in the text.
ContentElement
Property Detail

elementHeight

property
elementHeight:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5, Flash Lite 4

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

elementWidth

property 
elementWidth:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5, Flash Lite 4

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

graphic

property 
graphic:DisplayObject

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5, Flash Lite 4

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 removes the old graphic from the line and adds the new one.



Implementation
    public function get graphic():DisplayObject
    public function set graphic(value:DisplayObject):void
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
Runtime Versions: Flash Player 10, AIR 1.5, Flash Lite 4

Creates a new GraphicElement instance.

The registration point of the graphic aligns with the upper-left corner of the region defined by elementHeight, elementWidth and elementFormat.baselineShift. The graphic is not scaled to match the size of the region. If the GraphicElement has an eventMirror, the elementWidth and elementHeight properties, and not the graphic, determine the size and position of the resulting mirror region. If a loader is used, the graphic might not be loaded at the time the text line and the mirror regions are created.

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 to the element as a unit. Use flash.text.engine.TextRotation constants for this property. The default value is flash.text.engine.TextRotation.ROTATE_0.

See also

GraphicElementExample.as

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;        
        }
    }    
}