3 Replies Latest reply on Jun 7, 2006 7:12 AM by Newsgroup_User

    Calculator

    SimonMcC
      Can any one help. I'm a bit of a beginer with programming in general and even more so with Director and lingo. What I want to do is create a type of calculator where in a text box, if the user clicks on a button numbered 1 then 1 appears as the text. And when the user then presses 2 the text = 12 not 3 or for some reason when I try 151!

      I would be very greatful for the help

      Simon
        • 1. Re: Calculator
          Level 7
          Just append the new number to the member's text property.

          on mouseUp
          member("YourTextMemebersName").text =
          member("YourTextMemebersName").text & "2"
          end



          • 2. Re: Calculator
            SimonMcC Level 1
            Dave,
            Thanks for your help, but with this lingo used on an expanded calculator with 10 diget buttons will I have a problem? While 1 + 2, with your code would = the desired 12, I think 2 + 1 would also = 12 and not the desired 21

            Is there any chance you could expand your answer just a bit.

            Many many thanks
            Simon
            • 3. Re: Calculator
              Level 7
              "While 1 + 2, with your code would = the desired 12, I think 2 + 1 would
              also = 12 and not the desired 21"

              Why do you think that? You are just appending a digit to the end of the
              existing text. You can make a single behavior and attach it to each of your
              number buttons ( 0 - 9) assuming you are using Director's built in button
              control. If you are using your own custom graphics you will need to modify
              the code a little. This is just a starting point, if you want to do other
              thing like limit the number to 10 digits you will have to add that to the
              script as well.

              --------------------
              property spriteNum

              on mouseUp me
              member("display").text = member("display").text &
              sprite(spriteNum).member.text
              end