2 Replies Latest reply on Aug 11, 2007 12:44 PM by procks

    Help with dynamic text

      Hi, I was just wondering if anyone could help me out.

      Basically, I'v created a dynamic text on the main timeline with an instance name of "score". I then created a button within 2 movie clips. The idea is that when the button is pressed, I add to the score. The code I'm using on the button is
      _root.score.text +=20;

      I'm not an experienced actionscripter, I was wondering if anyone could maybe tell me where I'v gone wrong and what to do to make this work. Thanks xD
        • 1. Re: Help with dynamic text
          Greg Dove Level 4
          Well officially the .text property of a textfield is a string so what will happen is that the 20 gets turned into string and concatenated (or appended) the the string value in the text property.

          Can you clarfify the problem? Is your textfield changing or not?

          If it is changing then you will need to do something like:
          _root.score.text = Number(_root.score.text)+20;
          That requires that a valid number already exists in the textfield. It might be safer to track the score in a separate variable and then assign it to the textfield's text property each time it changes.

          If its not changing then try putting a trace in to see what's happening:
          trace("textfield is:"+_root.score)
          _root.score.text +=20;

          If you see 'undefined' then it may just be a typo - perhaps you called it Score with an uppercase S for example. If its defined and nothing is visible then it could be that you've embedded fonts without numbers or something like that.

          • 2. Re: Help with dynamic text
            procks Level 1
            Hey GWD,

            Thanks for your reply. I was really stuck there but I'm finally making progress again and you've also helped me achieve better understanding on how dynamic text works. Thanks!