2 Replies Latest reply on Dec 1, 2008 8:25 PM by corpkid2

    Increment Value of a Dynamic Text Field

    corpkid2
      Hi all,

      I have a probably very easy question (but I'm very new to flash and actionscripting). Anyhow, here's the deal.

      A have a dynamic text box (I just created it using the text tool and changing the type to dynamic). The instance is called HelpRequestText. What I need to do is start this off at 0 from frame 1. Then at various times through the movie, have that value incremented by 1 per a schedule I have (e.g. at minute 2:24 it goes up one, then again at 4:18, etc.). Also, there are three buttons, and when the user clicks on one of them, I need that value to increment by 1 more immediately.

      So I guess the two questions are - 1) How do I set the text file to zero, then update it according to a schedule of keyframes I have laid out?

      2) How can I have the buttons increment it by 1 when they are clicked?

      Thanks for your help!
      Dominic
        • 1. Increment Value of a Dynamic Text Field
          Ned Murphy Adobe Community Professional & MVP
          In AS2 you can assign a variable to the textfield in the Properties panel as well as an instance name. So all you really need to do is declare a variable in the actions layer (var incrementingValue = 0; for example) and assign that same variable name to the textfield in the Properties panel. Whatever you change the value of that variable to in code will be displayed in the textfield. (I hope... it's been a long time since I've gone that way)

          Another approach is to assign the text to the textfield as the value changes... HelpRequestText.text = String(incrementingValue);
          • 2. Re: Increment Value of a Dynamic Text Field
            corpkid2 Level 1
            My problem was that I was getting a NaN. I think this was because the buttons are on their own timeline inside a movie clip (so I can do some advanced stuff with them). I was struggling with global variables until I realized you don't declare it like a normal variable. Instead of:
            var _global.MyVariable you should use:
            _global.MyVariable. Anyways, it's working perfectly now.

            What I did was this:

            1) REPLACE HELP REQUESTED NUMBER WITH A DYNAMIC TEXT BOX TWO DIGITS WIDE WITH INSTANCE NAME HelpRequestText
            --> copy in place instance across keyframes on that layer

            2) ADD THIS TO EACH HELP BUTTON:
            _global.testvar = _global.testvar+1;
            _root.HelpRequestText.text = _global.testvar;


            3) ADD THIS TO THE MAIN TIMELINE AT THE BEGINNING

            _global.testvar = 0;
            HelpRequestText.text = _global.testvar;


            4) ADD THIS TO THE MAIN TIMELINE ON "HELP INCREASE" FRAMES:
            _global.testvar = _global.testvar+1;
            HelpRequestText.text = _global.testvar;

            Great! Now I just gotta go and fix 8 movies and recompile them in ZINC. Ugh. Thanks for your help!