3 Replies Latest reply on Mar 16, 2010 3:36 PM by Ned Murphy

    Help with variables!


      Firstly, allow me to appologize for my screenname, I attempted 31 different names and none of them would work, rather bad if you ask me.


      I attempted a project over a year ago, which failed miserably after I had no help no matter where I asked, but circumstances are bringing me to pick that project up again.


      To outline my project, it's a very large simulator, created in Excel, and it's got several very large databases on it. However the most simplest thing; variables, stopped me from using flash to finish the project. I don't know how to explain it more simpler, I have just been on over a dozen websites on the front page of google which attempt to explain the use of variables and text boxes and none of them worked.


      Let me get to it, my problem is that no matter what I attempt, I have dynamic text boxes which always return a value of NaN. I'll provide my method of having an input box return values for the dynamic boxes.


      My first step, is having an input text box, with variable set as; rlevel, and a dynamic text box as; points. I have a button which applies the input text into the dynamic box.


      This is the actionscript applied to the button;


      on (release) {




      It's pretty basic to start with, however no matter the method i've attempted it always returns NaN. Another alternative i've tried is setting the dynamic and input boxes to other variables and made the calculation an individual variable;




      on (release) {




      This once again, returns Nan into my dynamic text box, and undefined into my input box.


      I'm very fluent with mathematical formula's and I have alot of additions to make, however like stated I cannot get past the most basic part of my project once again despite following numerous tutorials on the matter, which to note say to do exactly what i've already done. One example method as reference is this;




      on (press) {




      This is no different than my own, and it still returns NaN. I have successfully made a dynamic>input text box function, just by;


      on (release) {




      and the string in level is returned correctly, it just refuses to do it with a calculation. I'm very lost and puzzled and do not wish to give up my project once again. Kudo's to ANYONE who can explain what is happening. hopefully this time someone will bother to help me.

        • 1. Re: Help with variables!
          Ned Murphy Adobe Community Professional & MVP

          Chances are your first attempt at getting a screenname would have flown, but for whatever reason their signup system rejects anything you enter... I found after trial and error that just ignoring the message gets you the name you wanted (unless it truly is taken).


          As far as your troubles go with the textfield, I recommend avoiding the use of the var element of the textfields and just manipulate their text property.  Give the textfields an instance name in the properties panel instead of specifying a var for them.  Let's say you name one myPoints and the other myLevel.  Your button code would look like...


          on (release) {

               myPoints.text = String((Number(myLevel.text)-1)*4);



          While AS2 is often very forgiving if you don't cast things as String or Number, it just helps make sure things are geared to work properly if you use them.  A textfield holds string values, so to treat them as numbers you cast them as Number(), and if the result is being assigned to a textfield, then casting it to be a String() is appropriate.


          If you ever move on to AS3, it is not at all forgiving and the var element of textfields no longer exists.

          • 2. Re: Help with variables!
            namesaretaken Level 1

            Thanks for the detail, more than appreciated and works without a hiccup.


            I never thought of using an instance name to do calculations compared to setting the text as a variable. It'll take a bit of a while to get used to the method, but you have explained it very clear and made it understandable, it answered the question and gave a full explanation of the method in which the answer functions.


            I couldn't have asked for more, cheers.

            • 3. Re: Help with variables!
              Ned Murphy Adobe Community Professional & MVP

              You're welcome.  If you simply forget that the var aspect exists for textfields, you will be happier.  It took me a few years of suffering trying to use them to see the light.