Error handling in actionscript 3

When writing actionscript you allways forget to add some lines of code which are necessary on either syntax level or runtime level. Once you get the hand of it, you will understand what went wrong even before it happened. Sometimes you can struggle with the one-liner for many hours when the error only was an error so simple. Thats why this little post could come handy. If you should experience errors not described below, please post a comment and I´ll add it to the post. Hope this will help you a bit when pulling your hair.

1009: Cannot access a property or method of a null object reference.
This is a runtime error stating that an object has not been initialized. You can find where the error occurred if you look at the output below the error line. Here is an example of what you might experience:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ThumbHolder()
at ThumbsContainer()
at index/init()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at XMLParser/onComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

If you look at the second line, that states which method the error is located. You are trying to access properties in a variable that is not initialized. Try initializing the variable you are using. Example:


public function ThumbHolder() : void
{
yourGlobalVariable = new ObjectOfYourChoice();
...

1046: Type was not found or was not a compile-time constant: “SomeClass”.
This is an import error. The class “SomeClass” is undefined for the current context. Try importing the class on top of the class like this:


package
{
import thepackage.subpackage.SomeClass;
...

1065: Variable SomeClass is not defined.
This is a runtime error displayed in the output window.

ReferenceError: Error #1065: Variable ThumbsContainer is not defined.

The error states that there is access permission denied on a “Variable SomeClass”. This refers often to the class SomeClass rather than a variable. Check the class SomeClass and see if the class does have an access specifier(public/private/internal). If the class does not have a access specifier this error will occur because some code can´t access the class. If no access specifier is not defined, the class is default private. This means no class can use the “SomeClass” class. Try putting “public” in front of class and recompile/rebuild like this:


/* before */
package
{
class SomeClass
...
/* after */
package
{
public class SomeClass
...

1119: Access of possibly undefined property heigh through a reference with static type somepackage.subpackage.SomeClass.
This is a syntax error. This error line states that you are trying to access a property “heigh” from the SomeClass. SomeClass does not have a property called heigh. Have a look at the source column in the error console. The source column states what line of code the syntax error is located. If the SomeClass actually where Sprite or MovieClip, the property should have been height and not heigh.Try to change the line to the actual property and recompile/rebuild.

No comments yet.

Write a comment:

Captcha
Enter the letters you see above.