Skip to main content
Inspiring
September 30, 2009
Question

UpdateAllContainers() not working after i insert inlinegraphicelement

  • September 30, 2009
  • 1 reply
  • 674 views

Hi

Please find the attached flex project. Its a basic editor. After i insert image to my editor it does not show this but a space is covered by image. after i edit by delete or update my text image shows up. Please help what is missing

Thanks & Regards,

Imran

This topic has been closed for replies.

1 reply

Adobe Employee
October 6, 2009

Perhaps you are missing the event that updates when the graphic has been loaded?

Here is some example code that works:

package

{
    import flash.display.Sprite;
    import flash.events.Event;
   
    import flashx.textLayout.container.*;
    import flashx.textLayout.elements.*;
    import flashx.textLayout.events.StatusChangeEvent;

    /** Hell world text example with an inline graphic */
    public class InlineGraphic extends Sprite
    {
        private var _textFlow:TextFlow;
       
        public function InlineGraphic()
        {
            _textFlow = new TextFlow();
            _textFlow.fontSize = 48;
            var p:ParagraphElement = new ParagraphElement();
            _textFlow.addChild(p);
           
            var span:SpanElement = new SpanElement();
            span.text = "Hello ";
            p.addChild(span);
           
            // InlineGraphicElement has "auto" width/height so the size can't be calculated till the graphic is loaded
            var inlineGraphic:InlineGraphicElement = new InlineGraphicElement();
            inlineGraphic.source = "http://www.adobe.com/shockwave/download/images/flashplayer_100x100.jpg";
            p.addChild(inlineGraphic);
           
            var span2:SpanElement = new SpanElement();
            span2.text = " World";
            p.addChild(span2);
           
            // event sent when graphic is done loading
            _textFlow.addEventListener(StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGE,graphicStatusChangeEvent);

            _textFlow.flowComposer.addController(new ContainerController(this,400,200));
           
            // this call compose but the graphic hasn't been loaded from the source URL yet.
            // The actualWidth and actualHeight are zero. 
            _textFlow.flowComposer.updateAllControllers();
        }

        private function graphicStatusChangeEvent(e:StatusChangeEvent):void
        {
            // if the graphic has loaded update the display
            // actualWidth and actualHeight are computed from the graphic's height
            if (e.status == InlineGraphicElementStatus.READY || e.status == InlineGraphicElementStatus.SIZE_PENDING)
            {
                _textFlow.flowComposer.updateAllControllers();
            }
        }
    }
}