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 1 | 1120: 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
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.
kglad, it had the same code and it didn't have the error, that is why I created this discussion because it was so peculiar. You can't just tell me how it is when you haven't even seen it. Same code, no error. I'm very good with computers, I know different scripting languages including javascript, and I know how to identify syntax errors. This isn't a case of me not knowing what I am talking about.
Same code, two files, one gets a compiler error the other doesn't. Sorry kglad, but you're incorrect about that. There is only one frame, and there is no external .as file.
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.
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".
North America
Europe, Middle East and Africa
Asia Pacific