[ https://issues.apache.org/jira/browse/FLEX-34988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15054862#comment-15054862
]
Harbs commented on FLEX-34988:
------------------------------
Right. Here is the code I was using which works in AFB:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flashx.textLayout.compose.StandardFlowComposer;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.container.ScrollPolicy;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.EditManager;
import flashx.textLayout.elements.InlineGraphicElement;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.formats.TextLayoutFormat;
public class TLF_Bench_Images extends Sprite
{
private var oTextFlow:TextFlow;
private var oSprite:Sprite;
private var oController:ContainerController;
private var oEditManager:EditManager;
private var oFormat:TextLayoutFormat;
private var nWidth:Number = 750;
private var nHeigth:Number = 500;
private var sParagraphText:String;
private var sPageText:String;
private var sText:String = "";
private var nXPos:Number = 50;
private var nYPos:Number = 50;
private var iPages:int = 4; // Number of pages "DIN A4".
private var iColour:int = 0xFFFF66;
private var iPos_Start;
private var iPos_End;
private var iTextLength;
private var nTime_Start;
private var nTime_End;
private var timer:Timer;
public function TLF_Bench_Images()
{
loaderInfo.addEventListener(Event.INIT, initHandler);
}
public function initHandler(event:Event):void
{
loaderInfo.removeEventListener(Event.INIT, initHandler);
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
public function enterFrameHandler(event:Event):void
{
removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
doTest();
}
public function doTest():void
{
//------------------ Create a long Text. sText has a 100 "DIN A4" pages length more or
less.
sParagraphText = "aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa
aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa . \n \n";
sPageText = sParagraphText; // + sParagraphText + sParagraphText + sParagraphText + sParagraphText
+ sParagraphText + sParagraphText + sParagraphText + sParagraphText;
for ( var i:int = 0; i < iPages; i++) {
sText += sPageText;
} // for j
//------------------ Create de TextFlow and the elements we need to display it.
oTextFlow = new TextFlow();
oSprite = new Sprite();
oSprite.x = nXPos;
oSprite.y = nYPos;
this.addChild( oSprite );
oTextFlow = TextConverter.importToFlow( sText, TextConverter.PLAIN_TEXT_FORMAT );
oTextFlow.fontSize = 30;
oController = new ContainerController( oSprite, nWidth, nHeigth );
oController.verticalScrollPolicy = ScrollPolicy.ON;
//--
oTextFlow.flowComposer = new StandardFlowComposer();
oTextFlow.flowComposer.addController(oController);
oTextFlow.flowComposer.updateAllControllers();
//--
oEditManager = new EditManager();
oTextFlow.interactionManager = oEditManager;
//------------------ Scroll to the end of the Textflow.
iTextLength = oTextFlow.getText().length;
iPos_Start = iTextLength - 200;
iPos_End = iTextLength - 20;
oController.scrollToRange( iPos_Start, iPos_End );
//------------------ Get text BEFORE.
sText = oTextFlow.getText();
trace("BEFORE - sText.length:", sText.length, " oTextFlow.textLength:", oTextFlow.textLength);
//------------------ Add 3 images.
var oInlineGraphic:InlineGraphicElement;
oEditManager.selectRange( 10, 10 );
oInlineGraphic = oEditManager.insertInlineGraphic( "image/Image.png", 50, 30 );
oEditManager.selectRange( 20, 20 );
oInlineGraphic = oEditManager.insertInlineGraphic( "image/Image.png", 50, 30 );
oEditManager.selectRange( iTextLength - 10, iTextLength - 10 );
oInlineGraphic = oEditManager.insertInlineGraphic( "image/Image.png", 50, 30 );
//---------- Prove to uncomment this line.
//oController.verticalScrollPosition = 0;
sText = oTextFlow.getText();
trace("AFTER - sText.length:", sText.length, " oTextFlow.textLength:", oTextFlow.textLength
);
oEditManager.setFocus();
//------------------ Get text AFTER.
//------------------ RESULTS:
// We have added 3 images, but getText() function only returns the last one.
//
// NOTE_1: If you uncomment [oController.verticalScrollPosition = 0;] line after adding
the 3rd image, it returns the first two images.
// So, it seems getText() function only returns the images that have appeared on screen.
//
// NOTE_2: On the other hand, as you can see in the example, the [textLength] attribute
returns one more character than [getText().length].
//------------------ END
}
}
}
> Number of characters with images is wrong
> -----------------------------------------
>
> Key: FLEX-34988
> URL: https://issues.apache.org/jira/browse/FLEX-34988
> Project: Apache Flex
> Issue Type: Bug
> Components: TLF
> Affects Versions: Apache Flex 4.14.0
> Reporter: goratz
> Attachments: Image.png, TLF_Bench_Images.as, TLF_Bench_Images.fla
>
>
> Hi, I have a problem when I insert images in the text. When I get the text of the TLF
the number of characters is wrong. It only counts the images that are displayed.
> I build a test code to see the problem.
> -----------------------------------------------------------------------------------------------
> I added 3 images, but getText() function only returns the last one.
> NOTE_1: If you uncomment [oController.verticalScrollPosition = 0;] line after adding
the 3rd image, it returns the first two images.
> So, it seems getText() function only returns the images that have appeared on screen.
> NOTE_2: On the other hand, as you can see in the example, the [textLength] attribute
returns one more character than [getText().length].
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
|