4 Replies Latest reply on Nov 12, 2011 11:44 AM by Mike_Dobs

    Context/NativeMenu for TextInput

    Kywhod

      Hi all,

      I'm reading articles and forum topics for hours and can't figure out how to add a contextmenu to an inputtext :/

       

      The situation : I want when the user right click inside a textinput, a context menu shows up. (I'm working in AIR)

       

      What I've managed to do : right-click on the textinput (the border not inside) show the contextmenu but it is definitely not usable...

       

      Here is my inputtext which is inside a VGroup :

      <s:TextInput id="ownerText" text="{characterGrid.selectedItem.owner}" widthInChars="7"/>

       

      And a very simple code in creationComplete :

           var cm:NativeMenu = new NativeMenu();

           var itemMenu:NativeMenuItem = new NativeMenuItem("Goto");

           itemMenu.addEventListener(Event.SELECT, gotoFromNativeMenu);

           cm.addItem(itemMenu);

           ownertxt.contextMenu = cm;

      I tried with both NativeMenu and ContextMenu but same thing... Also

       

      I tried also this :

            var txt:TextField = ownerText.mx_internal::getTextField() as TextField;

            txt.contextMenu = cm;

      but it show me an error saying that getTextField is not found and it doesn't work either.

       

      Thanks for any help, i really need this feature :/

        • 1. Re: Context/NativeMenu for TextInput
          Flex harUI Adobe Employee

          I'm not sure you can control that for MX TextInput, but I think it might be

          possible for Spark TextInput

          • 2. Re: Context/NativeMenu for TextInput
            Kywhod Level 1

            In fact i'm using a spark textinput :/

            • 3. Re: Context/NativeMenu for TextInput
              JabbyPandaUA Level 3

              Assign custom ContextMenu instance to "textInput.textDisplay" instance, not to textInput itself, it will help in Flex 4.1

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                     xmlns:s="library://ns.adobe.com/flex/spark" 
                                     xmlns:mx="library://ns.adobe.com/flex/mx" 
                                     xmlns:local="*"
                                     creationComplete="onCreationComplete()">
                  <fx:Script>
                    <![CDATA[
                          protected function onCreationComplete():void
                          {
                              var menuLabel : String = 'Change Color';
                              var menuItem:ContextMenuItem = new ContextMenuItem(menuLabel);
                              var customContextMenu:ContextMenu = new ContextMenu();                                               
                              customContextMenu.customItems.push(menuItem);
                              textInput.textDisplay.contextMenu = customContextMenu;
                              richText.contextMenu = customContextMenu;
                          }
                      ]]>
                  </fx:Script>    
                  <s:layout>
                      <s:VerticalLayout/>
                  </s:layout>
                  <s:TextInput id="textInput"/>
                  <s:RichEditableText id="richText" editable="true" text="Hello world"/>
              </s:WindowedApplication>
              
              
              

                 And assigning custom NativeMenu to RichEditable component returns RTE both on Flex 4.1 SDK and latest Flex 4.5 SDK build, TLF is not yet ready to support NativeMenus for text components, may be a corresponding bug should be added....

              • 4. Re: Context/NativeMenu for TextInput
                Mike_Dobs Level 1

                textInput.textDisplay.contextMenu throws error as it does not contain this function, Flex 4.5.1