Skip to main content
Known Participant
February 24, 2010
Answered

StringTextLineFactory and backgroundColor

  • February 24, 2010
  • 1 reply
  • 1329 views

It doesn't appear that StringTextLineFactory supports the use of backgroundColor on the text layout format.  I noticed in the documentation of TextFlowTextLineFactory.createTextLines it mentions that if there are background colors they will be sent to the callback function as shapes but there is no mention of that in StringTextLineFactory.

StringTextLineFactory supports other adornments such as strike through so it would seem like backgroundColor should also work.

Thanks,

Joel Marks

This topic has been closed for replies.
Correct answer rdermer

I'm sorry, but this change is not going to get in to the 1.0 release. At this point we're pretty much only taking fixes for bugs that crash the Player.


It can be worked around.  Pasted below (thought I could attach but had to paste) is an example - it's really ugly - but it works.  Getting ahold of the backgroundManager was tricky.

Its guaranteed this won't work in future releases - but hopefully the bug will be fixed in those.

Richard

// ActionScript file

package
{
    import flash.display.DisplayObject;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.geom.Rectangle;
   
    import flashx.textLayout.compose.ISWFContext;
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.factory.StringTextLineFactory;
    import flashx.textLayout.factory.TextLineFactoryBase;
    import flashx.textLayout.formats.TextLayoutFormat;
    import flashx.textLayout.tlf_internal;
   
    use namespace tlf_internal;

    public class StringFactoryExample extends Sprite implements ISWFContext
    {
        private var stringFactory:StringTextLineFactory;
        private var factoryTextFlow:TextFlow;
        private var target:Sprite;
        static private var tempController:ContainerController = new ContainerController(null);
       
        public function StringFactoryExample()
        {
            target = new Sprite();
            addChild(target);
           
            stringFactory = new StringTextLineFactory();
           
            var format:TextLayoutFormat = new TextLayoutFormat();
            format.backgroundColor="0xffff00";
            format.fontSize = 24;
           
            stringFactory.compositionBounds = new Rectangle(25,25,100,100);
            stringFactory.spanFormat = format;
            stringFactory.text = "Hello";
            // hook in to catch the actual factoryTextFlow
            stringFactory.swfContext = this;
            factoryTextFlow = null;
            stringFactory.createTextLines(addTextLine);
        }
       
        public function callInContext(fn:Function, thisArg:Object, argArray:Array, returns:Boolean=true):*
        {
            // save it off for later
            if (!factoryTextFlow)
                factoryTextFlow = TextLineFactoryBase._factoryComposer.textFlow;

            if (returns)
                return fn.apply(thisArg, argArray);
            fn.apply(thisArg, argArray);
        }

       
        private function addTextLine(tl:DisplayObject):void
        {
            if (factoryTextFlow)
            {
                if (factoryTextFlow.backgroundManager)
                {
                    var shape:Shape = new Shape();
                    tempController.setCompositionSize(stringFactory.compositionBounds.width,stringFactory.compositionBounds.height);
                    factoryTextFlow.backgroundManager.drawAllRects(shape,tempController);
                    //shape.x = stringFactory.compositionBounds.x;
                    //shape.y = stringFactory.compositionBounds.y;
                    target.addChild(shape);
                }
                factoryTextFlow = null;
            }
            target.addChild(tl);
        }
    }
}

1 reply

February 24, 2010

You are correct that it is not supported. I'll log a request that we add backgroundColor support to the StringTextLineFactory.

Known Participant
February 25, 2010

Any chance that could make it into the 1.0 release?

Thanks,

Joel Marks

February 25, 2010

I'm sorry, but this change is not going to get in to the 1.0 release. At this point we're pretty much only taking fixes for bugs that crash the Player.