4 Replies Latest reply on Aug 4, 2006 8:29 AM by redshark

    var:number query

    redshark
      Hello all

      I have a small question about vars.

      I am making a questionnaire and the results are saved to an access database. There are some questions that require the user to input their 'top 5' from a selection and I have set it up so that when they select the option an number pad appears and they can enter their ranking for that option.

      I am using input text boxes for this and it all works great. I have encountered a problem where the access database needs these selections to have a data type of number not text.

      I have created vars for each text box (var textBox1:Number;) but the problem arises that when you view the text box it says 'undefined'. If I enter the number in the var it obviously enters the number I specified.

      I would like the text boxes to be blank rather than show 'undefined' or a number. Does anyone know how I might go about this?

      I have tried a few options but my limited AS knowledge hasn't got me far.

      Thanks in advance
      James
        • 1. Re: var:number query
          Level 7
          James,

          > I have created vars for each text box (var
          > textBox1:Number;) but the problem arises
          > that when you view the text box it says 'undefined'.

          That's because the variable you created does not yet have a value
          assigned to it. The thing is, even though you specified :Number, the
          content of text fields is always a string.

          This should do it for you ..

          var textBox1:String = "";

          ... which means the value of a string variable textBox1 is assigned to an
          empty string. You can't do that with a number, because there is no "empty"
          number -- know what I mean?

          It sounds like you're using the Var: field of the Property inspector to
          handle this, which may work fine -- Access is currently getting strings from
          you, even though you have the :Number suffix -- but the recommended practice
          is that you make use of the TextField.text property.

          Set up your collection of variables, as is. Keep them as numbers, just
          like you already have. Remove the text field Var: association for each text
          field in the Property inspector. For your submit button (or whatever
          mechanism posts the data), do something lik this (this would go in a
          timeline frame, *not* attached to the button -- which means your button will
          need an instance name) ...

          buttonInstanceNameHere.onRelease = function() {
          numberVariableA = Number(textFieldA.text);
          numberVariableB = Number(textFieldB.text);
          // etc.
          // then perform your variable post
          }

          Does that make sense?


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. var:number query
            redshark Level 1
            Hello David

            Thanks for the response.

            It seems to work, the text/number box is blank when the page is loaded....nice one!

            But I shall try to explain what happens in the movie as another problem has arisen and I'm a little unsure of how to look at solving it.

            I have uploaded a screenshot here that will help me explain what happens. So the user comes to the question and has to choose their 'top 5'. They click on 'ECCO Meeting' and the keypad to the right appears so then they select 1-5. The 'next' button then either sends the data to the DB or moves them to the next question.

            Now the problem that seems to have arisen is that when you click the number on the numberpad it doesn't appear in the textfield. I think i simply need to alter my keypad coding but I'm a little unsure to what may need changing.

            The keypad script is as follows:

            //KEYBOARD FUNCTIONS//
            //Numbers Array
            numbers = new Array("0","1", "2", "3", "4", "5");
            numberText = new Array("zero","one", "two", "three", "four", "five");
            //Set the Numbers in the text boxes, and create the onPress function for the numbers state.
            for(ip=0; ip<10; ip++){
            _root[numberText[ip]].keyLabel = numbers[ip];
            _root[numberText[ip]].onPress = function() {
            this.gotoAndPlay("down");
            q3option1Answer = q3option1Answer+this.keyLabel;
            gotoAndPlay("q3option1close");
            }
            }
            //Clear Button
            clear.onPress = function(){
            q3option1Answer = "";
            this.gotoAndPlay(2);
            gotoAndPlay("q3option1close");
            }

            For clarity, the 'q3option1Answer' is the var asigned to the textField. I have tried to use the textField instance name instead of the var name but to no avail. I'm sure it will be something simple but any help would be greatly appreciated.

            If you need any more info please let me know.

            Thanks in advance
            James
            • 3. Re: var:number query
              Level 7
              James,

              Really, the trouble you're having is that you're "in the dark," so to
              speak, about what goes on in your ActionScript once the SWF is compiled.
              You would definitely benefit from using some troubleshooting techniques,
              because they "light the way" and allow you to "see" what your variables and
              object references, etc., are doing.

              > _root[numberText[ip]].onPress = function() {
              > this.gotoAndPlay("down");
              > q3option1Answer = q3option1Answer+this.keyLabel;
              > gotoAndPlay("q3option1close");
              > }
              > }

              This this portion, for example, you should make sure that
              q3option1Answer is even visible from this location. It may be, but it may
              not. Use the trace() function to see the values of q3option1Answer and, for
              example, this.keyLabel, to make sure you're getting what you think you're
              getting. In fact, I would even trace "this" here (without quotes), to see
              if the button event handler is working at all.

              > I have tried to use the textField instance name instead
              > of the var name but to no avail.

              I'll bet you just popped it right into the existing code -- which is a
              bit like jumping into the deep end. ;) Test new concepts in a separate FLA
              first, as a kind of proof of concept.

              Check out this article, which illustrates the trace() suggestion, and a
              lot more.

              http://www.adobe.com/devnet/flash/articles/debugging_actionscript.html


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: var:number query
                redshark Level 1
                Hi David.

                I'll take a look at the article asap. The keyboard does work in other "text" instances, just now I've gone and thrown the "number" thing in it's time to get tracing :)

                Thanks for your help and time.

                James