3 Replies Latest reply on May 8, 2006 2:13 PM by

    Adding a math amount to dynamic text

      Hi all,

      I am working on a key pad that has a clock, allows you to enter a time amount and then count down that amount or add seconds to it.

      Here is the file: Flash movie

      As you can see there are a few things that I have been unable to do due to my beginning skill level:

      1a) 2 :34 PM isnt really a functioning clock, its just text. While it doesn't need to actually work like a real clock, it should have the colin blinking, and when you press any of the 1 - 9 numbers, it should clear away and present : 00, or : 0(number of pressed button).

      1b) How do I constrain the dynamic text box to only four numbers in the format of "xx : xx", where x is any number from 0 to 9, then a space on either side of the colin. Numbers get added from the right x first and get pumped to the next placeholder. (dc : ba)

      2) Again, pressing OK doesnt really countdown anything, it just says "cooking'. Upon pressing OK, how to I tell the button to count down to zero whatever the number is in the dynamic text box?

      3) The add button is supposed to add 2 seconds to whatever number (except the clock) is displayed in the dynamic text box, but it simply places a 2 next to the numbers. If 1:04 is displayed, then pressed Add should equate 1:06, not 1:042

      Here is the code:


      btn1.theNumber.text = "1";
      btn2.theNumber.text = "2";
      btn3.theNumber.text = "3";
      btn4.theNumber.text = "4";
      btn5.theNumber.text = "5";
      btn6.theNumber.text = "6";
      btn7.theNumber.text = "7";
      btn8.theNumber.text = "8";
      btn9.theNumber.text = "9";
      btn0.theNumber.text = "0";
      okButton.theNumber.text = "OK";
      cancel.theNumber.text = "CANCEL";
      addmore.theNumber.text = "Add";
      theCode.text = "2 : 34";



      btn1.onPress = function () {
      theCode.text += "1";
      };
      btn2.onPress = function () {
      theCode.text += "2";
      };
      btn3.onPress = function () {
      theCode.text += "3";
      };
      btn4.onPress = function () {
      theCode.text += "4";
      };
      btn5.onPress = function () {
      theCode.text += "5";
      };
      btn6.onPress = function () {
      theCode.text += "6";
      };
      btn7.onPress = function () {
      theCode.text += "7";
      };
      btn8.onPress = function () {
      theCode.text += "8";
      };
      btn9.onPress = function () {
      theCode.text += "9";
      };
      btn0.onPress = function () {
      theCode.text += "0";
      };
      okButton.onPress = function () {
      theCode.text = "Cooking";
      };
      cancel.onPress = function () {
      theCode.text = "2 : 34";
      };
      addmore.onPress = function() {
      theCode.text = theCode.text + 2;
      }

        • 1. Re: Adding a math amount to dynamic text
          Don McCahill Level 1
          I would do it in an entirely different way. Use numbers, and then display them as text. For instance, you do the math with the number and only change to text when you want to display it. For instance:

          if(myVar <10){
          myVar = "0"+myVar
          }

          Then you can also have code to check if the number is larger than 59, in which case it has to go to "00" and the hours digits have to increment.
          • 2. Re: Adding a math amount to dynamic text
            Hi Don,

            Thanks for the reply. I can understand the variable code you wrote. However, due to my skill level, I am a little unclear as to how it fits into the semantic whole of the design. I dont understand the connection between a button, the variables it calls, its result in the dynamic text field, and how it componds when other buttons are pressed using the code you gave me.

            Im sorry, I can understand snippets, but its very difficult to see the larger picture.

            • 3. Adding a math amount to dynamic text
              Ok,

              Here is what I have been trying, seen below, following what Don mentioned. However, I get an error if I keep the " " around the 0 in the last bit of code. And in reference to my first post, how do I expand the code to satisfy those questions. I'll keep trying!

              btn0.theNumber.text = "0";
              btn1.theNumber.text = "1";

              var numZero:Number = 0;
              var numOne:Number = 1;
              var numTwo:Number = 2;
              var numThree:Number = 3;
              var numFour:Number = 4;
              var numFive:Number = 5;
              var numSix:Number = 6;
              var numSeven:Number = 7;
              var numEight:Number = 8;
              var numNine:Number = 9;

              btn0.onPress = function () {
              theTime.text = numZero
              }
              btn1.onPress = function () {
              theTime.text = numOne
              }

              if(numZero <10){
              numZero = "0" + numZero
              }

              **Error** Scene=Scene 1, layer=actions, frame=1:Line 27: Type mismatch in assignment statement: found String where Number is required.
              numZero = "0" + numZero

              Total ActionScript Errors: 1 Reported Errors: 1