9 Replies Latest reply on Mar 1, 2009 6:59 PM by kglad

    Number Counter

      Hi,
      I have a dynamic text box embedded in a movie, movie1_mc. The character embedding has already been changed to numerals. I have a button, red_btn which is embedded in another movie, movie2_mc. My intention is to have the number in the text box to increase dynamically when red_btn.onPress. Is there a way to do that with onEnterFrame. The script I'm trying to use is as such.

      Any help would be greatly appreciated. Thanks.
        • 1. Re: Number Counter
          kglad Adobe Community Professional & MVP
          why would you use an onEnterFrame loop here?

          are you trying to increment one unit per button press?
          • 2. Re: Number Counter
            Level 1
            Yes, the intention is if the user presses and holds the button the counter would keep on running.
            • 3. Re: Number Counter
              kglad Adobe Community Professional & MVP
              your code implies movie1_mc.outputbase_num is a movieclip and that
              movie1_mc.outputbase_num.base_txt.outputbase_num is a variable.

              both of which may be true but would be a very poor choice of object names and is more likely the cause of your problem.

              what is the path/name to your textfield's associated variable, assuming you're using an associated variable to assign the text property to your textfield.
              • 4. Re: Number Counter
                Level 1
                I see,
                the dynamic text box has the instance name of base_txt. It is embedded in the movie clip, movie1_mc. The variable in the text box is called outputbase_num.

                Furthermore, I have a button, red_btn which is embedded in another movie clip with instance movie2_mc. This button onPress and onEnterFrame would induce the counter to keep running.

                The problem I face now is that the loop inputs the variable outputbase_num as a string although I have already declared it a number and set it to zero and embedded the characters in the text box as numbers. The result I get is (1111111111) .

                I might also have made a mistake in the syntax as I have just started using flash a week ago and not as adept at it as I would like.
                Thank You.
                • 5. Re: Number Counter
                  kglad Adobe Community Professional & MVP
                  you can simplify your coding by removing the references textfield variables. they never need to be used and only cause problems (one of which you're encountering).

                  use your textfield's text property to access its contents:

                  movie1_mc.base_txt.text;

                  the text property of textfields is always a string. among the ways to convert to a number (so you can increment), is to use the Number() function:

                  movie1_mc.base_txt.text = Number(movie1_mc.base_txt.text)+1;
                  • 6. Re: Number Counter
                    Level 1
                    Ok now it works when I use this script.

                    var Num:Number = 0;
                    red_btn.onPress = function () {
                    base_txt.text = Number(base_txt.text)+1;
                    }

                    However when i try to apply a onEnterFrame with the following script, it doesn't work anymore.

                    var Num:Number = 0;
                    red_btn.onPress = function () {
                    base_txt.onEnterFrame = function (){
                    this.text = Number(this.text)+1;
                    }
                    }
                    red_btn.onRelease = function(){
                    delete base_txt.onEnterFrame;
                    }





                    • 7. Re: Number Counter
                      kglad Adobe Community Professional & MVP
                      base_txt is a textfield, not a movieclip. only movieclips have onEnterFrame methods.
                      • 8. Re: Number Counter
                        Level 1
                        Yeah I got it now!
                        Thanks kglad!
                        • 9. Re: Number Counter
                          kglad Adobe Community Professional & MVP
                          you're welcome.