Description of Error
This error means that you’re trying to act on a property (could be a variable, a movie clip, etc) that Flash doesn’t recognize because it doesn’t technically exist yet. The name of the property flash is trying to access is displayed in the error, so it’s usually pretty easy to figure out exactly what’s gone wrong.
Adobe’s Official Writeup
You are attempting to access an undefined variable. For example, if the variable huh has not been defined, a call to it generates this error:
huh = 55;
This error can appear only when the compiler is running in strict mode.
(Adobe Error Reference)
Cause of the Error
- You have a typo in a variable name. Let’s say you have a movie clip on the stage called “MyMovie” and then in your actionscript you have somewhere
MyMvie.gotoAndStop(1). Did you notice the typo? Flash is looking for something called “MyMvie” which doesn’t exist – it’s an undefined property. You’ll get the following error: “Access of undefined property MyMvie.” - You haven’t declared the variable prior to instantiation. If you write
myMC = new MovieClip()without writingvar myMC:MovieClipsomewhere above it, you’ll get this error. Flash has no idea what myMC is until you declare it – it’s an unidentified property. You’ll get the following error: “Access of undefined property myMC.” - Your variable declaration is scoped in a way that keeps you from accessing it. If you declare a variable in a method, then that variable will only be accessible in that method. For instance,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
package { import flash.display.MovieClip; public class test extends MovieClip { public function test():void { MethodA(); MethodB(); } public function MethodA():void { var MyVar:int = 12; // declaring and instantiating MyVar in MethodA... } public function MethodB():void { trace(MyVar); // means you'll get an 1120 error when you try to call MyVar in method B. } } }
will return this error. MyVar exists only within MethodA – MethodB cannot see it.
Solutions to the Error
This one is pretty easy to track down and kill.
- Figure out what variable Flash sees as undefined. This will be the last word in the error – if the error says “Access of undefined property MyMvie” then you’re looking for MyMvie.
- First, check for a typo in that variable’s name. MyMvie should be MyMovie, in my example – fix that and you’re all set. If there’s no typo…
- …track that variable backwards to see where it’s declared. If it’s not declared, declare it. If it’s declared in a method whose scope prevents you from accessing it where you need to access it, declare it higher up the hierarchy. For instance, returning to our third example above, if we change the code so it looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package { import flash.display.MovieClip; public class test extends MovieClip { public var MyVar:int; // If you declare MyVar up here, you'll have access to it throughout the class. public function test():void { MethodA(); MethodB(); } public function MethodA():void { MyVar = 12; // here you just define it. } public function MethodB():void { trace(MyVar); // Now you can trace it. } } }
then it’ll work.
Other Articles About This Error
If you’ve read a useful writeup of this issue elsewhere on the internet, leave a comment and I’ll add it to this list.
Most Recent Comments