7 Replies Latest reply on Jul 29, 2009 4:36 AM by Bob Pierce

    TextField.menu - something stops it working

    Bob Pierce Level 1

      The following code is from the CS3 Language Reference. Pasted into a new file it works. Pasted into my current project it doesn't. Any ideas on what settings I might have that are disabling it?

       

      this.createTextField("news_txt", this.getNextHighestDepth(), 10, 10, 320, 240);
      news_txt.border = true;
      news_txt.wordWrap = true;
      news_txt.multiline = true;
      news_txt.text = "To see the custom context menu item, right click (PC) or ";
      news_txt.text += "control click (Mac) within the text field.";
      var menu_cm:ContextMenu = new ContextMenu();
      menu_cm.customItems.push(new ContextMenuItem("Resize", doResize));

       

      function doResize(obj:TextField, item:ContextMenuItem):Void {
          // "Resize" code here
          trace("you selected: "+item.caption);
      }
      news_txt.menu = menu_cm;

        • 1. Re: TextField.menu - something stops it working
          kglad Adobe Community Professional & MVP

          is your current project published for as2?

          • 2. Re: TextField.menu - something stops it working
            Bob Pierce Level 1

            Sorry, that was a rubbish post - tired and frustrated! Yes, both are AS2. (Initially the new file defaulted to AS3 and produced a compile error because of the spelling of Void.) By not working I mean that there are no compile errors and the text field is created ok but the context menu doesn't include the new "Resize" entry. The target .swf is loaded into a parent but it's very simple with no components.

             

            This morning I pasted the same code into the parent, main_mc, and it works; it doesn't work in any of the loaded .swfs. I load all the .swfs into main_mc at start up using MovieClipLoader.

            • 3. Re: TextField.menu - something stops it working
              kglad Adobe Community Professional & MVP

              create a test swf that contains just the code you displayed in your first message.  create another test loader swf that loads your test swf.  any problem?

              • 4. Re: TextField.menu - something stops it working
                Bob Pierce Level 1

                Yes the file works fine loaded into another file. I've tried adding the code to various sections of my testsite and can identify when it will work and when not. My loading sequence creates main_mc, then reads an XML file and creates within main_mc placeholder mcs ("trays") for every main menu tab, and within them creates placholder mcs for every sub menu item. I then replace each submenu placeholder with the appropriate .swf using MovieClipLoader. The code fails in any of these .swfs. One tray is used to hold common items that are normally hidden. In this case the tray placeholder itself is replaced by a .swf. The code works in this .swf and also in main_mc and in the top level loader_mc. So the code seems to work down to a certain level of nesting.

                • 5. Re: TextField.menu - something stops it working
                  Bob Pierce Level 1

                  Just to be clear, I said "replace" when I meant "load into".

                  • 6. Re: TextField.menu - something stops it working
                    kglad Adobe Community Professional & MVP

                    create a test project to see if there's a limit to the number of nestings that causes a context menu failure.

                    • 7. Re: TextField.menu - something stops it working
                      Bob Pierce Level 1

                      I have now reproduced the application's structure with a test suite and the custom menu works fine at a similar level to the swfs that fail. These swfs are the "pages" that represent each state in the app. Apart from being at the same level of nesting another thing they all have in common is an included AS file which handles navigation, slide shows etc. To test if this code is the problem I've had the test suite load one of these swfs and the context menu works fine. The problem, I guess, might be some interaction with the included AS file which won't show up in the test suite as it is structure only. I'm going to paste the include into one of the swfs and progressively comment out sections.

                       

                      Tracing "menu_cm.customItems[0].enabled" actually gives "true" so I'm begining to despair!