• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

textflow word right click

Guest
Aug 18, 2009 Aug 18, 2009

Copy link to clipboard

Copied

Hi,

I am using TLF in my application. the textflow contains text & inlinegraphics. I am trying to implement spell checker on my own. So I want to add the suggested words for the miss-spelt word. For that I want to know the word I have right cliked on. After that fetching it from library & getting the suggested words part is done.

So I need to add a right click event to the miss-spelt words and to know the word I have to look for(the word on which I have right clicked).

Thanks in advance.

TOPICS
Text layout framework

Views

3.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Aug 18, 2009 Aug 18, 2009

Copy link to clipboard

Copied

By default right click brings up the contextMenu.  I didn't find how to suppress the contextMenu on a given Sprite and then handle the right mouse event.  Might want to ask on a Flash forum.

One possibility: subclass ContainerController and override createContextMenu to create a custom contextMenu that is populated with spelling corrections.

Hope that helps,

Richard

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 18, 2009 Aug 18, 2009

Copy link to clipboard

Copied

Hi rdermer,

I don't want to suppress contextMenu and my requirement is the one possibility suggested by you. I need that only. But I am not able to get the word on which I have right clicked.

Also if the cursor is blinking some where else and I do right click some where else then I need the cursor to blink at the place where I have right clicked.

Just like MS Word.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Aug 19, 2009 Aug 19, 2009

Copy link to clipboard

Copied

Hi,

There are many ways to find the word which has been right-clicked but they all involve many steps. I've outlined one such way:

- Get the TextLine instance at which right click occured: Iterate through all text lines, get their bounds and check if the point at which the right-click occured falls in those bounds

- Once you have the target TextLine, iterate through all its atoms, get their bounds and check if the  point at which the right-click occured falls in those bounds.

- Once you have the target atom, use the ParagraphElement methods findNextWordBoundary and findPreviousWordBoundary to get the word.

Abhishek

(Adobe Systems Inc.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 01, 2009 Sep 01, 2009

Copy link to clipboard

Copied

Hi,

I too find the same issue with textflow control.

Please help us in getting best out of best solution for this issue.

Thanks in advance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2009 Oct 14, 2009

Copy link to clipboard

Copied

Hey all, not sure why this is marked possibly answered as they suggestions provided don't seem to answer the simple question, how can we define a contextmenu on a textflow?  For the matter I can't seem to get a contextmenu working on RichEditableText control or the textflow property of it either?  This seems like a pretty vital component to the text layout framework.  What can we do to implement this?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Oct 14, 2009 Oct 14, 2009

Copy link to clipboard

Copied

I can't speak to how you would add a ContextMenu to a RichEditableText object in Flex; I think you'd get a good answer to that if you post to the Flex forum.

If you are using TLF with straight Flash, the cleanest and most straightforward path is to make your own derived controller that inherits from ContainerController class and overrides the createContextMenu method.  I think Rich outlined this solution.

If you want to control the menu dynamically, so it pops up with different contents each time, it looks like there is a way. I don't have too much experience with this, but you could listen for the menuSelect event, which is sent right before the menu is displayed. For this, you would attach a listener to the controller's container, which is the Sprite that holds all the TextLines.

Here's a little more background on how this works in TLF. Flash handles ContextMenu events through the DisplayObject hierarchy, and since the TextFlow itself is not a DisplayObject, it doesn't handle the ContextMenu. The ContextMenu is handled by the container, which is the DisplayObject that was handed to TLF for showing the text. When you call updateAllControllers(), TLF calls into the Player to create TextLines, which are display objects, one per line, to hold the text.The TextFlow's flowComposer has one (or more) controllers, and each one has a container. This container is a DisplayObjectContainer (typically a Sprite, but you specify this). It is going to be the parent of the TextLines; when TLF does its update, at the end it adds the TextLines as children of the container. What this means for you is that the container is the DisplayObject that is going to be handling the context menu. Normally the controller handles it for you, by setting up the container with the context menu, and that's why the easiest path is to change the how the controller is doing this. If you think this won't work for you, let me know and we can discuss alternatives.

Now let's suppose you don't want a ContextMenu at all, you just want to get the right click yourself and handle it. Now I'm skating on thin ice here, because I haven't tried this, but it looks like the container should be getting a rightClickEvent (see InteractiveObject rightClickEvent). We don't listen for this, but you certainly could, either by getting the container from the ContainerController and adding a listener for the rightClickEvent to the container directly. Alternatively, you could add this same code to a custom version of the ContainerController. Your listener could do whatever it wants with the right click event.

If you want to do selection or hit detection on right click, you can read through Abhishek's post on how to do this. Another way to do this would be to piggy-back on our text selection code to do this, and call SelectionManager.setNewSelectionPoint(). This is a tlf_internal function (sorry!) but you can still call it.

There were a lot of questions spread out through the thread, so I'm not sure which ones you were asking about. If I missed yours, please just ask.

Hope this helps,

- robin

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2009 Oct 14, 2009

Copy link to clipboard

Copied

Robin, thank you a ton for your guidance on this one.  I think I can figure out a good solution to this problem based on your insights here. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 18, 2009 Oct 18, 2009

Copy link to clipboard

Copied

Hi Robin thanks for the reply after a long time. I tried to do this in manner.

Here is the code, what i worked around.

public

var _textContainer:Sprite = null;

_textContainer =

new Sprite();

_textContainer.addEventListener(MouseEvent.CLICK, setCurrentCell);

_canvasTarget.rawChildren.addChild(_textContainer); // Added the container to the object of TLF.

SetCurrentCell Function :

public

function setCurrentCell(e:MouseEvent):

void

{

var

currentChar:String;

var

currentWord:String;

var

currentIndex:int;

var

tmpIndex:int;

var

tmpChar:String;

var left:String=''

;

var right:String=''

;

Application.application.mainF.currentCell = _textFlow;

//Get the current word

if

(rightClickFlag)

{

rightClickFlag =

false

;

//setBlinking(e);

//trace(_textFlow.interactionManager.activePosition)

currentIndex = _textFlow.interactionManager.activePosition;

//trace(_textFlow.getCharAtPosition(_textFlow.interactionManager.activePosition))

currentChar = _textFlow.getCharAtPosition(_textFlow.interactionManager.activePosition)

//Traverse back

tmpIndex = currentIndex;

tmpChar = currentChar;

while

(1)

{

//Also need to consider for images in between

if(tmpChar == ' ' || tmpIndex<0 || tmpChar == ''

)

{

startPos = ++tmpIndex;

break

;

}

tmpIndex--;

tmpChar = _textFlow.getCharAtPosition(tmpIndex);

if(tmpChar.charCodeAt() == 65007 || !(tmpChar.charCodeAt() is Number))

//65007 char code of image as a block in plain text format

{

startPos = ++tmpIndex;

break

;

}

left += _textFlow.getCharAtPosition(tmpIndex);

trace

(tmpChar.charCodeAt());

}

var tmpLeft:String = ''

;

for (var

i:int = (left.length - 1); i >= 0; i--)

tmpLeft+= left.charAt(i);

left = tmpLeft;

//Traverse ahead

tmpIndex = currentIndex;

tmpChar = currentChar;

while

(1)

{

//Also need to consider for images in between

if(tmpChar == ' ' || tmpChar == ''

)

{

endPos = tmpIndex;

break

;

}

tmpIndex++;

tmpChar = _textFlow.getCharAtPosition(tmpIndex);

if(tmpChar.charCodeAt() == 8233 || !(tmpChar.charCodeAt() is

Number))

{

endPos = tmpIndex;

break

;

}

right += _textFlow.getCharAtPosition(tmpIndex);

//trace(tmpChar.charCodeAt());

}

currentWord = StringUtil.trim(left + currentChar + right);

//Alert.show(currentWord)

//_textFlow.interactionManager.setFocus();

//_textFlow.interactionManager.setSelection(startPos, endPos);

}

}

But still i am not able to blink the cursor on right click.

Can you help me furthere, that where i am going wrong.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 19, 2009 Oct 19, 2009

Copy link to clipboard

Copied

Thanks Robin for the detailed explaination.

I am not facing problem with ContextMenu. I am trying to get the blinking cursor where I right click. I tried with Sprite(_textContainer).dispatchEvent(new MouseEvent(MouseEvent.CLICK,true,false,evt.stageX,evt.stageY));
&
TextFlow(_textFlow).dispatchEvent(new MouseEvent(MouseEvent.CLICK,true,false,evt.stageX,evt.stageY));

but still not getting the blinking cursor where I have right clicked.

Can you please tell where I am going wrong or what can I do for it?

Actually I am trying to use the Textflow editmanager's active cursor position to get the word where I am then using that word I am adding the suggestions to context menu if the word is misspelt.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

Robin,
As come to your suggestions, we tried at our end. Its not working.
We are facing really tough time with the issue of Right Click functionality on over Text Layour Framework.
The issue is as follows..
- As we are using the Text Layout Framework in our application. When the user right clicks on any word on the Text Layout Editor, then the cursor should starts blinking at that position.
So can you help me in finding any workarounds or suggestions.
Please help us...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Oct 30, 2009 Oct 30, 2009

Copy link to clipboard

Copied

LATEST

I wrote some example code which shows one way to convert an arbitrary (x, y) location in a container to a selected location in the text.The idea is that you should be able to listen for the right mouse click, get the x,y location from it, and use something like this code to do the selection. This code works in the Player; with a little more work I think the right click would work in AIR.

Let me know how it works!

Here it is:

package {
   
    import flash.display.Sprite;
    import flash.events.MouseEvent;
   
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.conversion.TextConverter;
    import flashx.textLayout.edit.SelectionManager;
    import flashx.textLayout.elements.TextFlow;
   
    public class ClickToPositionExample extends Sprite
    {
       
        public function ClickToPositionExample()
        {
            super();

            // Set up the TextFlow with some text

           var textFlow:TextFlow = setupFlow();

            textFlow.interactionManager = new SelectionManager();
           
            var controller:ContainerController = new ContainerController(this, 500, 300);
            textFlow.flowComposer.addController(controller);
            textFlow.flowComposer.updateAllControllers();
            textFlow.interactionManager.selectRange(0, 0);  
            textFlow.interactionManager.setFocus();
           
            // simulate clicking at (x, y)
            var x:Number = 100;
            var y:Number = 100;
            var event:MouseEvent = new MouseEvent(MouseEvent.MOUSE_DOWN, true, false, x, y);
            controller.container.dispatchEvent(event);
            textFlow.flowComposer.updateAllControllers();
        }

          public function setupFlow:TextFlow

          {

            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>";
             return TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);

          }
    }   
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines