Skip navigation
Androidblowtech
Currently Being Moderated

Scene 1, Layer 'Layer 1', Frame 1, Line 1     1120: Access of undefined property counter.

Sep 17, 2012 11:40 PM

So I am in an intermediate flash course right now, right at the beginning where everything is very introductory. We were told to download .fla file that gives an example of a run-time error. It's a simple for loop (I know javascript, so I can already make sense of it, and its written properly). Here is the syntax:

 

for (counter=1;counter<10;counter++) {

    trace(counter);

}

 

it counts 1-9 rather than the desired 1-10. Easy Peasy, right? Well here is the problem:

 

When I open a new file, and write the EXACT same thing in the actions window so the files are pretty much identical (except for the file names) and then run it I get the compiler error of:

Scene 1, Layer 'Layer 1', Frame 1, Line 11120: Access of undefined property counter.

 

I even cut and paste the code from the file we were provided to my new file and it did the same thing but there is nothing wrong with the code.

 

I was using CS4 and have upgraded to CS6 and I am having nothing but problems with my flash program. Help isn't working, code hints aren't showing up, and then this. This worries me because what if I am writing a script for my class, and it's perfect, but it's giving me errors when there are none.

 

Any ideas people???

 

(I also just created another discussion in the Flash Pro - General forum in regards to my other problems if any keeners can help me out.)

 

Thanks for any help

 
Replies
  • Currently Being Moderated
    Sep 18, 2012 1:12 AM   in reply to Androidblowtech

    for (counter=1;counter<10;counter++) {

        trace(counter);

    }

     

    Well... you placed counter = 1. But you didn't define counter as a variable. So therefore if you didn't declare it as a variable in the beginning of the script, it'll end up as an undefined property.

     

    The solution to your problem would be

     

    for(var counter:int = 1; counter<10; counter++){

    trace(counter);

    }

     

    I used "var counter:int = 1" to declare the counter variable as an interger.

     

    Hope that helps.

     
    |
    Mark as:
  • kglad
    62,035 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 18, 2012 2:48 PM   in reply to Androidblowtech

    if the supplied file contained the same code and the same publish settings, it would have the same error.

     

    counter must be declared somewhere prior to that for loop.  it could be in another frame or another layer but somewhere there is, at least:

     

    var counter

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 18, 2012 9:25 AM   in reply to Androidblowtech

    you're welcome .

     
    |
    Mark as:
  • kglad
    62,035 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 18, 2012 2:50 PM   in reply to Androidblowtech

    that's fine.

     

    but for anyone else checking this, the only way that the same code could trigger an error in one test and not trigger an error in another test would be different and unequal tests.  in particular, using strict mode in one test would trigger an error while disabling strict mode would not trigger an error.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 19, 2012 2:48 PM   in reply to Androidblowtech

    Although it is consider good practice to declare a variable before its first use, AS 3.0 doesn't require it. But if you enable "strict mode" the Flash will force you to declare the variable. In strict mode the use of a variable before it is declared results in "Error 1120: Access of undefined property 'YourPropertyNameHere'".

    Note that the setting for strict mode is stored at the file level. In your case, the FLA that you downloaded and used as-is didn't have strict mode enabled (ergo, no error 1120) but when you copied and pasted the same code into a new FLA  error 1120 is the result. Why does this happen? Well, if I'm not mistaken Flash CS6 enables strict mode by default.

    To disable strict mode for an individual file do: "File -> ActionScript Settings -> (deselect) Strict Mode".

    
     
    |
    Mark as:
  • kglad
    62,035 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 19, 2012 3:31 PM   in reply to G_Crosby

    (i already mentioned that twice.  a 2nd person explaining it a third time might help the op but mostly is worth mentioning to help others that might be more open to learning.)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points