Skip to main content
Participating Frequently
November 3, 2009
Question

Help with EditManager

  • November 3, 2009
  • 2 replies
  • 974 views

Hello,

I am building a Spark-based TLF text editing component I'll be using in major application and I admit I am struggling.

It sure would be nice if Adobe was able to release the source code for the demo editors they have up on the Lab site, but I digress.

Anyway, I stumbled upon the EditManager and its capabilities today.

The way I am going about this is attaching a new EditManager instance to the textFlow.interactionManager property of a Spark TextArea control.

One thing I note when I do this is that the cursor doesn't appear in the TextArea with the above property set.  That seems like it is a bug but it could be that the way I am going about trying to use an EditManager instance with the Spark TextArea is not best practice.

I am struggling to insert a link into the TextArea with the EditManager.applyLink method.

I am doing something like this:

var em:IEditManager = textArea.textFlow.interactionManager as IEditManager;

var stringLength:int = myString.length; // this is the length of the string that should show up as the title of the hyperlink

var startPos:int = textArea.selectionActivePosition; // this should be where the cursor currently is

em.insertText(myString); // this should insert the text at the location of the cursor in the TextArea - which it does

em.selectRange(startPos,startPos+stringLength); // this should select the word that was just added to the TextArea

em.applyLink(myURL); // this should transform the word I just added to a hyperlink

The above doesn't work.  selectRange() isn't working, therefore applyLink obviously won't work.

Can someone help me get over this hurdle?

This topic has been closed for replies.

2 replies

Inspiring
May 17, 2010

I had the same problem as well when using the insertText method, I couldnt get the selectRange method to work.  But I found that when using the overwriteText method the selectRange would work.  The problem is if you dont have any text selected it overwrites the first char infront of the cursor.  So I had to find that char and re-insert it along with the text I was overwriting with.

This seems to work for me, although it is kind of a hack.

em.overwriteText(myString+textArea.text(substring(textArea.selectionActivePosition,textArea.selectionActivePosition+1));

em.selectRange(startPos,startPos+stringLength);

Adobe Employee
November 4, 2009

Pretty much this same code is working for me. When you say the link doesn't get applied, do you see it change style? By default, when the link is applied the text will appear in blue and underlined. If the text is editable, as this is (because it has an EditManager), you have to use a modifier key when you click to activate the link, since a regular click is interpreted as a selection. On the Mac, this is a command click. Another thing to look at is whether, when you go to insert the text, you have a valid selection. But if the text is appearing at the right place, you must.

Here's the program I wrote, based on your code:

package {
   
    import flash.display.Sprite;
    import flash.events.MouseEvent;
   
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.conversion.TextConverter;
    import flashx.textLayout.edit.EditManager;
    import flashx.textLayout.elements.TextFlow;
   
    public class ClickToPositionExample extends Sprite
    {
       
        public function ClickToPositionExample()
        {
            super();
           
            // Set up the TextFlow with some text
            const markup:String = "<flow:TextFlow xmlns:flow='http://ns.adobe.com/textLayout/2008' fontSize='14' textIndent='15' paragraphSpaceAfter='15' paddingTop='4' paddingLeft='4'>" +
                "<flow:p>The following excerpt is from <flow:span>Ethan Brand</flow:span> by <flow:span>Nathaniel Hawthorne</flow:span>.</flow:p>" +
                "<flow:p><flow:span>There are many </flow:span><flow:span fontStyle='italic'>such</flow:span><flow:span> lime-kilns in that tract of country, for the purpose of burning the white marble which composes a large part of the substance of the hills. Some of them, built years ago, and long deserted, with weeds growing in the vacant round of the interior, which is open to the sky, and grass and wild-flowers rooting themselves into the chinks of the stones, look already like relics of antiquity, and may yet be overspread with the lichens of centuries to come. Others, where the lime-burner still feeds his daily and nightlong fire, afford points of interest to the wanderer among the hills, who seats himself on a log of wood or a fragment of marble, to hold a chat with the solitary man. It is a lonesome, and, when the character is inclined to thought, may be an intensely thoughtful occupation; as it proved in the case of Ethan Brand, who had mused to such strange purpose, in days gone by, while the fire in this very kiln was burning.</flow:span></flow:p><flow:p><flow:span>The man who now watched the fire was of a different order, and troubled himself with no thoughts save the very few that were requisite to his business. At frequent intervals, he flung back the clashing weight of the iron door, and, turning his face from the insufferable glare, thrust in huge logs of oak, or stirred the immense brands with a long pole. Within the furnace were seen the curling and riotous flames, and the burning marble, almost molten with the intensity of heat; while without, the reflection of the fire quivered on the dark intricacy of the surrounding forest, and showed in the foreground a bright and ruddy little picture of the hut, the spring beside its door, the athletic and coal-begrimed figure of the lime-burner, and the half-frightened child, shrinking into the protection of his father's shadow. And when again the iron door was closed, then reappeared the tender light of the half-full moon, which vainly strove to trace out the indistinct shapes of the neighboring mountains; and, in the upper sky, there was a flitting congregation of clouds, still faintly tinged with the rosy sunset, though thus far down into the valley the sunshine had vanished long and long ago.</flow:span></flow:p></flow:TextFlow>";
            var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
            textFlow.interactionManager = new EditManager();
            var em:EditManager = textFlow.interactionManager as EditManager;
            em.selectRange(0, 0);
           
            var controller:ContainerController = new ContainerController(this, 500, 300);
            textFlow.flowComposer.addController(controller);
            textFlow.flowComposer.updateAllControllers();
           
            var myString:String = "LinkThis";
            var stringLength:int = myString.length; // this is the length of the string that should show up as the title of the hyperlink       
            var startPos:int = textFlow.interactionManager.absoluteStart; // this should be where the cursor currently is       
            em.insertText(myString); // this should insert the text at the location of the cursor in the TextArea - which it does
           
            em.selectRange(startPos,startPos+stringLength); // this should select the word that was just added to the TextArea
           
            em.applyLink("http://www.w3.org"); // this should transform the word I just added to a hyperlink
     }   
}