 {
     /**
      *  @private
-     *  Create a single Configuration used by all Text instances.  
-     *  It tells the TextContainerManager that we want TLF1.1 compatibility
-     *  for the selection length.  Pre TLF2, the selection length 
-     *  was textFlow.length-1 and did not include the final paragraph terminator.  
-     *  For TLF2, the selection length is textFlow.length which includes
-     *  the final paragraph terminator.
-     */
-    private static var staticConfiguration:Configuration;
-
-    /**
-     *  @private
-     */
-    public function FTETextFieldTextContainerManager(container:Sprite)
-    {       
-        // See comment on staticConfiguration variable.
-        if (staticConfiguration == null)
-        {
-            staticConfiguration = 
-               Configuration(TextContainerManager.defaultConfiguration).clone();
-            staticConfiguration.compatibilityVersion = 1.1;
-        }
-    
-        super(container, staticConfiguration);
+     */
+    public function FTETextFieldTextContainerManager(container:Sprite, configuration:IConfiguration = null)
+    {
+        super(container, configuration);
     }
     
     /**

    {
        var foundStyle:Object = _styleSheet.getStyle(styleSelector);
        if (foundStyle != null)
        { 		
            for (var p:* in foundStyle)
            {
                var propStyle:Object = foundStyle[p];

        return attr;
    }
}

/** @private Used when needing an HTML view of things. */
class HTMLHelper
{
    /**
     *  @private
     */
    private static var plainTextImporter:ITextImporter;
    
    /**
     *  @private
     */
    private static var plainTextExporter:ITextExporter;
    
    /**
     *  @private
     */
    private static var collapsingHTMLImporter:ITextImporter;
    
    /**
     *  @private
     */
    private static var preservingHTMLImporter:ITextImporter;
    
    /**
     *  @private
     */
    private static var htmlExporter:ITextExporter;
    
    /**
     *  @private
     */
    private static function initClass():void
    {
        var format:TextLayoutFormat;
        var config:Configuration;
        
        // Create an importer for plain text.
        plainTextImporter =
            TextConverter.getImporter(TextConverter.PLAIN_TEXT_FORMAT);
        
        // Create an exporter for plain text.
        plainTextExporter =
            TextConverter.getExporter(TextConverter.PLAIN_TEXT_FORMAT);
        
        // Create an importer for TEXT_FIELD_HTML_FORMAT that collapses whitespace.
        // Note: We have to make a copy of the textFlowInitialFormat,
        // which has various formats set to "inherit",
        // and then modify it and set it back.
        config = new Configuration();
        format = new TextLayoutFormat(config.textFlowInitialFormat);
        format.whiteSpaceCollapse = "collapse";
        config.textFlowInitialFormat = format;
        collapsingHTMLImporter =
            TextConverter.getImporter(TextConverter.TEXT_FIELD_HTML_FORMAT, config);
        collapsingHTMLImporter.throwOnError = false;
        
        // Create an importer for TEXT_FIELD_HTML_FORMAT that preserves whitespace.
        // Note: We have to make a copy of the textFlowInitialFormat,
        // which has various formats set to "inherit",
        // and then modify it and set it back.
        config = new Configuration();
        format = new TextLayoutFormat(config.textFlowInitialFormat);
        format.whiteSpaceCollapse = "preserve";
        config.textFlowInitialFormat = format;
        preservingHTMLImporter =
            TextConverter.getImporter(TextConverter.TEXT_FIELD_HTML_FORMAT, config);
        preservingHTMLImporter.throwOnError = false;
        
        // Create an exporter for TEXT_FIELD_HTML_FORMAT.
        htmlExporter =
            TextConverter.getExporter(TextConverter.TEXT_FIELD_HTML_FORMAT);
    }
    
    initClass();
    
    /**
     *  @private
     */
    private static var factory:TextFlowTextLineFactory =
        new TextFlowTextLineFactory();
    
    private var _field:FTETextField;
    
    public function HTMLHelper(field:FTETextField)
    {
        this._field = field;
    }
    
    /**
     *  @private
     *  If htmlText is set, composeHtmlText is called each time the text lines
     *  are invalidated.  The setters for many of the properties invalidate
     *  the text lines.  So although _htmlText is set to null, if there is no
     *  styleSheet, to indicate to the htmlText getter that it needs to import
     *  the html from the textFlow, we need the orginal htmlText for the cases 
     *  where we need to regenerate the html text lines.
     */
    public var explicitHTMLText:String = null;
    
    /**
     *  @private
     *  When we render the htmlText using TLF,
     *  this object represents the formatting for TLF.
     *  Every time the defaultTextFormat is set,
     *  this object is released because it is invalid.
     *  It is regenerated just in time to render the htmlText.
     */
    public var hostFormat:ITextLayoutFormat;
    
    /**
     *  @private
     *  When we render the htmlText using TLF,
     *  this object represents the rich text to be displayed.
     *  It is created by using TLF's HTML importer to import the htmlText.
     */
    public var textFlow:TextFlow;
    
    /**
     *  @private
     *  When we render the htmlText using TLF,
     *  this object composes the textFlow
     *  (with the hostFormat applied to it)
     *  to create TextLines in this Sprite.
     */
    public var textContainerManager:TextContainerManager;
    
    /**
     *  @private
     */
    public var _htmlText:String = null;
    
    /**
     *  @private
     */
    public var _styleSheet:StyleSheet = null;
    
    //----------------------------------
    //  htmlImporter
    //----------------------------------
    
    /**
     *  @private
     */
    private function get htmlImporter():ITextImporter
    {
        // Note that which importer we return depends on the value
        // of condenseWhite was at the time that htmlText was set,
        // not on the current value of condenseWhite,
        // since it could change between htmlText being set
        // and the TextLines being composed.
        return _field.testFlag(FTETextField.FLAG_EFFECTIVE_CONDENSE_WHITE) ?
            collapsingHTMLImporter :
            preservingHTMLImporter;
    }   
    
    /**
     *  @private
     */
    public function composeHTMLText(compositionWidth:Number,
                                     compositionHeight:Number):void
    {
        var textFlow:TextFlow = textFlow = htmlImporter.importToFlow(explicitHTMLText);
        
        // Unless there is a styleSheet, _htmlText is now invalid
        // and needs to be regenerated on demand,
        // because with htmlText what-you-set-is-not-what-you-get.
        if (!_styleSheet)
            _htmlText = null;
        
        if (!textFlow)
            return;
        
        textFlow.addEventListener(MouseEvent.CLICK, linkClickHandler);
        
        textFlow.addEventListener(
            StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGE,
            _field.inlineGraphicStatusChangeHandler);
        
        if (!textContainerManager)
            textContainerManager = new FTETextFieldTextContainerManager(_field);
        
        textContainerManager.compositionWidth = compositionWidth;
        textContainerManager.compositionHeight = compositionHeight;
        
        textContainerManager.editingMode = EditingMode.READ_ONLY;
        
        textContainerManager.hostFormat = hostFormat;
        
        textContainerManager.swfContext = _field.fontContext as ISWFContext;
        
        textContainerManager.setTextFlow(textFlow)
        
        // Add a formatResolver if there is a style sheet.  Force a flow
        // composer to be created, if there isn't one, so the format resolver
        // will be used.
        if (_styleSheet && !textFlow.formatResolver)
        {
            textFlow.formatResolver = new FTETextFieldStyleResolver(_styleSheet);
            textContainerManager.beginInteraction();
            textContainerManager.endInteraction();
        }
        
        textContainerManager.updateContainer();
        
        var bounds:Rectangle = textContainerManager.getContentBounds();
        
        _field._textWidth = Math.round(bounds.width);
        _field._textHeight = Math.round(bounds.height);
        
        // TLF takes care of clipping so none should be needed here.
        _field.clipWidth = _field._textWidth;
    }
        
    /**
     *  @private
     */
    private function linkClickHandler(event:FlowElementMouseEvent):void
    {
        // Need to remove the event: portion of the href if it has one.
        // Only dispatch the event if it has the event portion.
        var href:String = LinkElement(event.flowElement).href;
        if (href.indexOf("event:") == 0)
        {
            var textEvent:TextEvent = new TextEvent(TextEvent.LINK);
            textEvent.text = href.substring(6);
            _field.dispatchEvent(textEvent);
        }
    }
    
    /**
     *  @private
     */
    public function getHtmlText(fieldText:String):String
    {       
        if (_htmlText == null)
        {
            // We can optimize the default case
            // that there is no text or hmtlText.
            if (fieldText == "")
            {
                _htmlText = "";
            }
            else
            {
                // Import the plain text into a TextFlow,
                // and then export the TextFlow into HTML.
                if (!textFlow)
                    textFlow = plainTextImporter.importToFlow(fieldText);
                _htmlText = String(htmlExporter.export(
                    textFlow, ConversionType.STRING_TYPE));
            }
        }   
        
        return _htmlText;
    }
    
    /**
     *  @private
     */
    public function set styleSheet(value:StyleSheet):void
    {   
        _styleSheet = value;
        
        var textFlow:TextFlow = textFlow;
        if (textFlow && textFlow.formatResolver)
            textFlow.formatResolver = null;
    }
    
    /**
     *  @private
     */
    public function getText():String
    {
        var rslt:String;
        
        // If we don't already have a TextFlow,
        // create one by importing the htmlText.
        if (!textFlow)
            textFlow = htmlImporter.importToFlow(_htmlText);
        
        // Export plain text from the TextFlow.
        return String(plainTextExporter.export(
            textFlow, ConversionType.STRING_TYPE));
    }
}