Skip to main content
Participating Frequently
September 18, 2012
Question

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

  • September 18, 2012
  • 2 replies
  • 4441 views

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

This topic has been closed for replies.

2 replies

Participant
September 19, 2012

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".


kglad
Community Expert
Community Expert
September 19, 2012

(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.)

Known Participant
September 18, 2012

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.

Participating Frequently
September 18, 2012

It is, yes and no, and I do appreciate the response. The thing that was getting me was in the file provided to me in our course the variable was not declared yet it still functioned.

Perhaps I should just forget about it...

Thanks for your time!

kglad
Community Expert
Community Expert
September 18, 2012

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