Skip to main content
Participating Frequently
January 11, 2010
Question

How to use a DisplayObject as the source of a <flow:img/>

  • January 11, 2010
  • 1 reply
  • 2169 views

I have a text flow that I am loading from an external file that has this snippet of xml in it:

...

<flow:p>

     <flow:img styleName="chart" id="fig1" height="250"/>

</flow:p>

...

What I need to do is put a Flex chart in place of that image. I tried the following before passing my TextFlow into the thing that displays it.

var flow:TextFlow = TextConverter.importToFlow("sample.xml", TextConverter.TEXT_LAYOUT_FORMAT);

var figs:Array = flow.getElementsByStyleName("chart");

     for (var i:int = 0; i < figs.length; i++) {

          if (figs is InlineGraphicElement) {

               var id:String = FlowElement(figs).id;

               var figure:DisplayObject = getFigure(id);// <-- this returns an instance of my chart

               InlineGraphicElement(figs).source = figure;

          }

}

The result is that nothing happens, I don't see my chart, just an empty space. My understanding was that you can set a DisplayObject as the source of the InlineGraphicElement as described at http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/frames.html?http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html&http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/all-classes.html&filter_flex=4&filter_flashplayer=10&filter_air=1.5

The difference is that I am not creating my flow programatically but I wouldn't expect that to make a difference. I am using Flex 3.4 though. Could that be the difference?

This topic has been closed for replies.

1 reply

Adobe Employee
January 12, 2010

Do you have something afterwards that will force it to update with the changes? I'm thinking something like this:

flow.flowComposer.updateAllControllers();

- robin

Participating Frequently
January 12, 2010

Yes. After setting the sources, I pass the textFlow into my "viewer" which creates the "pages" of my document, then calls textFlow.flowComposer.updateAllControllers().

What I ended up doing to work around this for now, was to listen for the COMPOSITION_COMPLETE event then loop through all the elements with the styleName "chart" and through some various apis find the line that the blank image is on, then find the column it is in, then find the coordinates of the line in that column and place my chart in directly over the blank image. It works pretty well, but I feel like I shouldn't have to do that. Plus, if you have a SelectionManager or EditManager, the charts are no longer interactive so you can't mouse over them to get tool tips (not a huge deal but I was hoping doing it the "right way" may not have that problem)