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

how to get context menu of textflow container ?

Guest
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

i tried to add custom items to tf container but they are not shown ?
Does TF control its CM and forbid its CM to be modified ?

Any ideas ?
TOPICS
Text layout framework

Views

2.2K

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
Participant ,
Mar 24, 2009 Mar 24, 2009

Copy link to clipboard

Copied

Best way to add context menu items is to add an event listener to the container for ContextMenuEvent.MENU_SELECT (i think that's the right one). In the event handler, you can access the context menu via event.target as ContextMenu and then manipulate custom items, which will actually be in the context menu by the time the user sees it. Also, by handling this way you can control which items are displayed/enabled based on the current selection, etc. BTW, if you add custom items and add listeners to those, you'll probably want to make sure that you use weak listeners for the menu items.

--Brent

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
Mar 24, 2009 Mar 24, 2009

Copy link to clipboard

Copied

container itself does not dispatch ContextMenuEvent. So your point seems not valid.

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
Participant ,
Mar 24, 2009 Mar 24, 2009

Copy link to clipboard

Copied

You're right, I'm sorry about that. What I meant was you add the event listener to the context menu for the container (container.contextMenu property). You may have to create a new ContextMenu and assign it to the container if it doesn't have one, but I think that TLF does this when you create a DisplayObjectContainerController for a container.

Alternatively, if you are in a position to be able to extend DisplayObjectContainerController for use with your container, you can do that and then override the protected method 'processContextMenuSelectHandler', which will be called automatically whenever a user 'right' clicks in the container. You can override in your class, make sure you call super, and then add items to the customItems array on the context menu. This is probably the cleanest way to do it if you can. But you should be able to handle outside the context of the container controller if you wish. If you do it outside of the container controller, keep in mind that (I'm fairly certain) the TLF container controller will also be handling the same event that you are, and you might need to adjust the priority of the listener depending on what exactly you're trying to do.

Hope this helps.

--Brent

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
Mar 25, 2009 Mar 25, 2009

Copy link to clipboard

Copied

thanks alot , this shines some light. i will try this and post result.

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
Apr 01, 2009 Apr 01, 2009

Copy link to clipboard

Copied

Hi, i am also trying to access the default context menu which appears on the textflow, but not able to do do.
and i also want the solution to add context menu or update the existing one process.

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
Apr 01, 2009 Apr 01, 2009

Copy link to clipboard

Copied

i did not try the suggested one yet since it will need user at least to invoke the CM at least once. My current approach is to add a sprite to current textline when selection happens then add a CM to that sprite. it works well .

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
Explorer ,
Jul 28, 2010 Jul 28, 2010

Copy link to clipboard

Copied

What I did was extend containerController to allow me to pass in the contextmenu for the textflow here is that simple class:

package classes.Email
{
    import flash.display.Sprite;
   
    import flashx.textLayout.container.ContainerController;
    import flash.ui.ContextMenu;
   
    public class CustomController extends ContainerController
    {
        public var cm:ContextMenu;
        public function CustomController(container:Sprite, con:ContextMenu, compositionWidth:Number=100, compositionHeight:Number=100)
        {
            cm = con;
            super(container, compositionWidth, compositionHeight);
        }
        protected override function createContextMenu():ContextMenu{
            cm.clipboardMenu = true;
            return cm;
        }
    }
}

This seems to work perfect!

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 ,
Sep 23, 2010 Sep 23, 2010

Copy link to clipboard

Copied

LATEST

hi can u tell me with an mxml example, how to create a new context menu? or add some items in the existing context menu?

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