7 Replies Latest reply: Jan 26, 2011 5:23 AM by Rob Dillon RSS

    Dynamice Text adding Numbers

    Fumph Community Member

      I dont know why, but I am having the hardest time! All I want is for there to be a movieclip, and when I click it my textfield adds a number! I swear I have looked everywhere but nothing! Does anyone know how to do such? Thanks!

        • 1. Re: Dynamice Text adding Numbers
          Rob Dillon CommunityMVP

          What version of Flash are you using and which version of Actionscript are you using? What does you code look like now?

          • 2. Re: Dynamice Text adding Numbers
            Fumph Community Member

            Flash pro CS5 and AS3(Because I'm in the Actionscript 3 forum), but currently I have no code because every code I try just doesn't work. There will be compiler errors, text wont show, syntax error! I hope that helps!

            • 3. Re: Dynamice Text adding Numbers
              Rob Dillon CommunityMVP

              You might be surprised at how many people who post in this forum are actually using AS2. In any case, you could use something like this:

               

              buttonInstanceName.addEventListener(MouseEvent.MOUSE_UP,myUp);

               

              dynamicTextInstanceName.text = "0";

               

              function myUp(event:MouseEvent):void {

              var myTempNum:int = parseFloat(dynamicTextInstanceName.text);

              myTempNum += 1;

              dynamicTextInstanceName.text = myTempNum.toString();

              }

              • 4. Re: Dynamice Text adding Numbers
                Fumph Community Member

                Haha I bet! So I tried this code in my project, but! It still doesn't count up! I am thinking it has to do with the fact that I go to a new scene once I click this button. Here is the code for my main scene:

                 

                stop();

                goal1.addEventListener(MouseEvent.MOUSE_DOWN, shootBall1);
                goalCount.text = "0";
                function shootBall1(e:MouseEvent):void
                {
                var myTempNum:int = parseFloat(goalCount.text);

                  myTempNum +=  1;

                  goalCount.text = myTempNum.toString();

                trace("Goal!");
                gotoAndPlay("shoot1","shootGoal");

                 


                }

                 

                And once it goes back to my main scene it restarts the counting because of the "goalCount.text = "0";". I believe that's my problem, do you have any advice?

                • 5. Re: Dynamice Text adding Numbers
                  Rob Dillon CommunityMVP

                  You can set the inital value of the text conditionally:

                   

                  if(goalCount.text == "") {

                    goalCount.text = "0";

                  }

                  • 6. Re: Dynamice Text adding Numbers
                    Fumph Community Member

                    I'm sorry but, it still doesn't work. I don't know what is wrong with it but it doesn't count! Even when I took out the "gotoAndPlay". Its... being difficult! Do you think you could fix it?? Maybe I could e-mail you the FLA. But its okay if you cant.

                    • 7. Re: Dynamice Text adding Numbers
                      Rob Dillon CommunityMVP

                      Sure, send me a private message and I'll send you an upload address to send the file to.