4 Replies Latest reply on Oct 11, 2009 1:48 PM by Grover1

    Getting NaN for Variable

    Grover1 Level 1

      I put the following actionscript into the first frame labeled “actions”:

      _global.iCount:Number = 0;

      I then attached this script to a button, in the second frame:

      on (release) {

                      iCount = iCount + 1;



      The debugger gives no value for “iCount” on the frame script, and yields a “NaN” value for iCount after the button is released.  At first it worked, now it doesn’t.  Thanks, in advance, for your help, Taylor

        • 1. Re: Getting NaN for Variable
          Rothrock Level 5

          Generally with _global variables you must use _global when assigning them and can omit it when accessing them. But in practice it is just better to always use the _global so that you know it is global and not a local variable. So I think




          would probably be the best bet.


          I would also recommend that you stop using on(event) handlers. Unless you are target Flash 5 publish it is outdated and makes it harder for folks to help you. Also if you ever want to move to AS3 you won't be able to use them because they have been removed. Here is a great article about the issue:



          • 2. Re: Getting NaN for Variable
            Grover1 Level 1

            Rothrock, thanks for the help.  I tried putting "_global.iCount++" in various parts of the code.  I also tried following the suggestions in the article that you linked.  I'm still lost.  I'd like to move to AS3, but I'm hooked up with VCT online tutorials, and they have nothing on video for AS3, that I've found.  I'll just keep at it till i happen upon it by chance.  -Taylor

            • 3. Re: Getting NaN for Variable
              Rothrock Level 5

              Oh I think I know what might be happening. When you set a property of an object you can't type it. So in your declaration you should do this:




              You should be getting an error message when you try and compile this. But really using _global is also not a really great strategy. Many of the reasons for wanting to use _global are due to the fractured way using on(event) coding makes you write code. A lot of the scope issues go away if you start using frame code.

              • 4. Re: Getting NaN for Variable
                Grover1 Level 1

                Rothrock,  Thanks for the info.  I'm fairly lost with AS2 and have decided

                to junk what I have so far, purchase CS4, and invest the time in learning

                AS3.  I think that it'll save me trouble in the long run. -Taylor