flash.text.engine

# GraphicElement - AS3

Package | flash.text.engine
Class | public final class GraphicElement
Inheritance | GraphicElement ContentElement 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

More examples

Adding GraphicElement and GroupElement objects

Related API Elements

ContentElement
GroupElement
TextBlock

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | elementFormat : 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
|  | eventMirror : 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
|  | groupElement : GroupElement [read-only] The GroupElement object that contains this element, or null if it is not in a group. | ContentElement
|  | rawText : String [read-only] A copy of the text in the element, including any U+FDEF characters. | ContentElement
|  | text : 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
|  | textBlock : flash.text.engine:TextBlock [read-only] The TextBlock to which this element belongs. | ContentElement
|  | textBlockBeginIndex : int [read-only] The index in the text block of the first character of this element. | ContentElement
|  | textRotation : String The rotation to apply to the element as a unit. | ContentElement
|  | userData : * Provides a way for an application to associate arbitrary data with the element. | ContentElement

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined 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
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Public Constants
Hide Inherited Public Constants
Show Inherited Public Constants

| Constant | Defined By
--- | --- | ---

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`.

Related API Elements

GroupElement
Examples How to use this example
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.
Copy

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

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00