5 Replies Latest reply on Jun 25, 2006 5:28 PM by Newsgroup_User

    Can't set dynamic text in MC via AS

    ricklecoat Level 1
      Firstly, I'm VERY new to both Flash and ActionScript, so please bear with me if I ask stupid questions.

      I have a very simple button -- the symbol contains just a shape and an (empty) dynamic text box (with the instance name "theText"). I want to place several instances of the button and use AS (attached to Frame 1 of the root timeline) to set the text for each button by targeting the dynamic text box. I placed one instance to start with, but can't even get this one to show text on the button.

      The button instance on the stage is called theButton. The dynamic text inside the button symbol is named theText.
      My AS code is attached to Frame 1 and is as follows:

      this.theButton.theText.text= "SOMETHING";

      This should, to my thinking, give the button the text "SOMETHING" at runtime. But when I test the movie the button is still blank, with no text. What am I doing wrong?
      Many thanks;

      Rick
        • 1. Re: Can't set dynamic text in MC via AS
          Level 7
          > this.theButton.theText.text= "SOMETHING";

          Change behavior of theButton to movieclip so that you can refer to objects inside of it. Then..

          theButton.theText.text = "SOMETHING";

          // Lose the "this" part, it is useless here.

          tralfaz


          • 2. Re: Can't set dynamic text in MC via AS
            ricklecoat Level 1
            tralfaz:
            Thanks very much for that, I hadn't realised that elements inside buttons couldn't be targeted. I wonder why that is? Anyway, rather than just change the button behaviour to MC (which would presumably have stopped it from presenting UP, OVER states etc.) I wrapped the button in a further MC symbol (with the dynamic text now in the mc, not the button itself) and all is well.

            Thanks again. As I said, I'm about as newbie as you can get with this stuff, so any and all help is hugely appreciated.
            Rick
            • 3. Re: Can't set dynamic text in MC via AS
              Level 7
              "ricklecoat" <webforumsuser@macromedia.com> wrote in message news:e7ljgo$5sv$1@forums.macromedia.com...
              > tralfaz:
              > Thanks very much for that, I hadn't realised that elements inside buttons
              > couldn't be targeted. I wonder why that is? Anyway, rather than just change the
              > button behaviour to MC (which would presumably have stopped it from presenting
              > UP, OVER states etc.) I wrapped the button in a further MC symbol (with the
              > dynamic text now in the mc, not the button itself) and all is well.
              >
              > Thanks again. As I said, I'm about as newbie as you can get with this stuff,
              > so any and all help is hugely appreciated.
              > Rick

              Welcome,
              Yeah, you would think that since the button has an instance name and the dynamic text field inside of it has an instance name that
              you could reference the text field but for whatever reason you can't do it. Most of my buttons are movieclips these days because
              they are more flexible. You can have the button have any kind of exotic behaviors without the restrictions that buttons have. You
              just have to make your own up,over,down states or animated states inside of it.
              Learning Flash has a lot to do with learning about all these non-obvious quirks.
              tralfaz


              • 4. Re: Can't set dynamic text in MC via AS
                kglad Adobe Community Professional & MVP
                you can reference a textfield on a buttons "timeline". but you can't give the textfield an instance name that flash will recognize.

                flash assigns its own instance name for the textfield and if you use that instance name you'll have no problem assigning the text property for the textfield.

                but it's not very convenient so, using a movieclip button makes much more sense.
                • 5. Re: Can't set dynamic text in MC via AS
                  Level 7
                  > flash assigns its own instance name for the textfield and if you use that
                  > instance name you'll have no problem assigning the text property for the
                  > textfield.

                  Can you retrieve the instance name of the dynamic text box at run time somehow to be able to use it?
                  tralfaz