• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Debugging ActionScript 3.0 Errors

Community Expert ,
Sep 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

First, click File > Publish Settings > Flash, tick the "Permit debugging" checkbox, then click OK and retest. 

By ticking "Permit debugging" you will see more detailed/helpful error messages. Error messages' exact contents depend on the error type (compile-time or run-time), the exact error and the location (timeline or class file) of your problematic code. But, in all scenarios (except for errors that occur during an asynchronous event like file loading), the error message will indicate the exact line number of the problematic code, if you tick "Permit debugging".


You may find some error messages need no explanation (like compiler error "1021: Duplicate function definition"). But if you need further explanation, check the Flash help file Appendixes (Help > Flash Help > ActionScript 3.0 and Components > ActionScript 3.0 Reference for the Adobe Flash Platform > Appendixes), where you'll find Compiler Errors and Run-Time Errors which comprise a complete listing of all error messages often with additional and sometimes helpful information. As of this writing that link is http://help.adobe.com/en_US/FlashPlatform/reference/ActionScript/3/app endixes.html but that may change especially as updated help files are published by Adobe.

This is the first place you should check when you encounter an error message that you do not completely understand. The additional information may be enough to save hours of hair-pulling frustration.

But if that's not enough help, don't be afraid to use a search engine. Searching for "Flash as3 error xxxx" should bring up all sorts of information. Some of it may be helpful.

Below are the error messages (in numeric order) most commonly cited in the ActionScript 3 forum and help for resolving.

1009: Cannot access a property or method of a null object reference.

This is the most common error posted on the Adobe Flash-related Forums.  Fortunately, most of these errors are quick and easy to fix (assuming you read the Permit Debugging section).  If there is only one object reference in the problematic line of code, you can conclude that object does not exist when that line of code executes.   For example, if there is no object mc on-stage,

var mc:MovieClip;

  1. mc.x = 0;

is the simplest code that would trigger a 1009 error.  The variable mc has been declared but is null because no movieclip exists and and it has not been created.  Trying to access the x property (or any other property of mc) is going to result in a 1009 error because you cannot access a property of a null (or non-existant) object.

To remedy this problem, you must create the referenced object either on-stage or with actionscript. To create the object with code, use the "new" constructor:

var mc:MovieClip = new MovieClip();

  1. mc.x = 0;

Precisely the same error will occur in many different guises.  Here's the same error trying to reference a null object method:

var s:Sound;

  1. s.play();

If there's more than one object in the problematic line of code, for example:

mc1.x = mc2.width+mc2.x;

use the trace() function to find which object(s) is(are) null:

trace(mc1);

trace(mc2);

mc1.x = mc2.width+mc2.x;

Of course, typos are every coders burden and are a common cause of 1009 errors.  Instead of comparing two names and trying to confirm they are the same, (eg, an instance name in the properties panel and an actionscript name), it's more reliable to copy the name from one location and paste it to the other.  Then you can be certain the names are the same.

There are, however, more obtuse ways to trigger a 1009 error when you create and delete objects on-stage and especially if you use timeline tweening.   I have seen some 1009 errors that are impossible to diagnose without checking the history panel.   And if that panel is cleared or the problem was created far enough in the past that the steps causing the error are no longer present in the history panel, there's no way (known to me) to deduce what caused the error.  However, those errors can still be fixed.

If you are certain you have an on-stage object whose instance name (in the properties panel) matches your actionscript reference and it is in a frame that plays no later than your code referencing that object, you may need to take a few steps backwards to solve the problem.  But first make sure that frame plays before your object reference.

You can always confirm that by using the trace() function:  Place a trace("frame") in the keyframe that contains your object.  (If you have a document class it will need to extend the MovieClip class to do this.) And place a trace("code") just above the problematic line of code and test. 

If you see "code" and then your error message, your code is executing before your frame plays. Fix your code so it does not execute until the object exists.  I cannot tell you how to do that because the solution will vary depending on your project.

If you see "frame" then "code", you have confirmed your object exists before your code tries to reference it so something else is causing the problem. This always boils down to Flash being confused because you have or had more than one object with that reference name.

To solve this problem, move the on-stage object to its own layer, clear all keyframes in that layer except one, copy its reference from your actionscript and paste into the properties panel.  Use movie explorer to confirm there is no actionscript creating a duplicate reference and there is no other on-stage object with the same reference.   Then test. 

There will be no 1009 referencing that object if those steps are followed and the actionscript referencing the object executes no sooner than the keyframe containing the object. Now, add other needed keyframes and change the object properties, as needed.

Another way this error can occur is when trying to reference a loader's content property before loading is complete: 

var loader:Loader = new Loader();

  1. loader.load(new URLRequest("test.swf"));  // make sure you have a test.swf in the correct directory

trace(MovieClip(loader.content).totalFrames);  // will trigger a 1009 error

Because a loader's content property is null until loading is complete, use an Event.COMPLETE listener and listener function before referencing the loader's content.

var loader:Loader = new Loader();

  1. loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeF);
  2. loader.load(new URLRequest("test.swf"));  // make sure you have a test.swf in the correct directory

function completeF(e:Event):void{

      trace(MovieClip(loader.content).totalFrames);  // no error

}

Also, a DisplayObject's root and stage properties are null until the object is added to the display list.  This error frequently occurs in a DisplayObject's class file where the object is created using the "new" constructor, the object's class constructor executes and a stage reference is made before the object is added to the display list. For example:

var custom_mc:Custom_MC = new Custom_MC();

addChild(custom_mc);

will trigger this error if Custom_MC looks something like:

package {

      import flash.display.MovieClip;

      public class Custom_MC extends MovieClip {

            public function Custom_MC() {

                  // stage is null at this point triggering a 1009 error

                  this.x=stage.stageWidth/2; 

            }

      }

}

To test if the problem is whether an object has been added to the display list, you can use:

trace(this.stage); 

added above the problematic line of code.  The trace output will be null.  For example:

package {

      import flash.display.MovieClip;

      public class Custom_MC extends MovieClip {

            public function Custom_MC() {

                  trace(this.stage); 

                  this.x=stage.stageWidth/2;

            }

      }

}

To remedy this problem, use the Event.ADDED_TO_STAGE listener before trying to reference the stage:

package {

      import flash.display.MovieClip;

      public class Custom_MC extends MovieClip {

            public function Custom_MC() {

                  this.addEventListener(Event.ADDED_TO_STAGE,init);

            }

            private function init(e:Event):void{

                  this.x=stage.stageWidth/2;  // stage is defined when this executes

            }

      }

}

1013: The private attribute may be used only on class property definitions.

This is commonly caused by mis-matched curly brackets {} in a class file in a line of code above the line that is mentioned in the error message.

1046:Type was not found or was not a compile-time constant: xxxx

You forgot to save the xxx class file, you have a typo or you need to import the needed class, xxxx..

To remedy the later, open the Flash help files>Classes>xxxx.  At the top you will see a package listed (eg, fl.controls) that you will use in the needed import statement.  Add the following to your scope:

import fl.controls.xxxx

(And, in this example, the needed class type is a component so you'll need that component in your fla's library, too.)

1061: Call to a possibly undefined method xxxx through a reference with static type flash.display:DisplayObject.

You are trying to reference a method defined on a MovieClip timeline using dot notation but the Flash compiler does not recognize that MovieClip as a MovieClip. To remedy explicitly cast the MovieClip.

For example, you have a function/method xxxx() defined on your root timeline which you are trying to reference using,

  1. root.xxxx();

To remedy, cast root as a MovieClip,

MovieClip(root).xxxx();

1067: Implicit coercion of a value of type xxxx to an unrelated type yyyy.

You are trying to assign an object from class xxxx a value from class yyyy. The most common error of this type seen on the Adobe forums is when trying to assign text to a TextField and the code forgets to use the TextField's text property:

var tf:TextField = new TextField();

tf = "This is test text.";  // should be using tf.text = "This is test text.";

1078: Label must be a simple identifier.

I get this error frequently because I'm speed typing and instead of a semi-colon, I have the shift-key pressed and add a colon at the end of a line of code.  Check the line of code mentioned in the error message and look for a misplaced colon (typically the last character in the line).

1118: Implicit coercion of a value with static type xxxx to a possibly unrelated type yyyy.

Often loaded content needs to be cast. For example, if you load a swf and try and check a MovieClip property (e.g., totalFrames), you will need to cast it as a MovieClip:

var loader:Loader = new Loader();

  1. loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeF);
  2. loader.load(new URLRequest("someswf.swf"));

function completeF(e:Event):void{

trace(e.target.loader.content.totalFrames):  // error expected

trace(MovieClip(e.target.loader.content).totalFrames));  // no error expected

}

Or, if you are loading xml:

var xml:XML;

var loader:URLLoader = new URLLoader();

  1. loader.addEventListener(Event.COMPLETE,completeF);
  2. loader.load(new URLRequest("somexml.xml"));

function completeF(e:Event):void{

xml = e.target.data // error expected

xml = XML(e.target.data); // no error expected

}

When you use getChildByName, the compiler only knows the object is a DisplayObject. If you want to use a property that is not inherited by DisplayObjects (e.g., mouseEnabled), you need to cast the object:

for (var i:int=0;i<4;i++) {

      var opBtn:Btn_operator = new Btn_operator(); // where the Btn_operator class  // extends an InteractiveObject class

      opBtn.name=i.toString();

      addChild(opBtn);

}

// then you can use:

for (i=0;i<4;i++) {

      opBtn = Btn_operator(getChildByName(i.toString()));

      opBtn.mouseEnabled = false;

}

1119: Access of possibly undefined property xxx through a reference with static type yyyy

You're trying to reference a property that doesn't exist for that class type.  You either have a typo or, if the Flash type is something like DisplayObject and, you are trying to reference a property of a class, which does have the property you are trying to reference, explicitly cast your object.

For example, if you have a DisplayObject (eg, dobj) added to the root timeline:

  1. root.dobj;  // may trigger a 1119 error

MovieClip(root).dobj; // will not trigger a 1119 error

In fact, almost always when you use root in ActionScript 3 you will need to case it as a MovieClip unless you have a document class that extends the Sprite class. In that situation, you will need to cast root as a Sprite:

MovieClip(root); // or

Sprite(root):

Also if, this.parent is a MovieClip:

  1. this.parent.ivar;  // may trigger a 1119 error

MovieClip(this.parent).ivar;  // will not trigger a 1119

If you're using one of your own class objects,

var opBtnParent:Sprite = new Sprite();

addChild(opBtnParent);

for (var i:int=0;i<4;i++) {

      var opBtn:Btn_operator = new Btn_operator();

      opBtnParent.addChild(opBtn);

}

// then you can use:

for (i=0;i<opBtnParent.numChildren;i++) {

      Btn_operator(opBtnParent.getChildAt(i)).mouseEnabled = false;

}

Or, you may be trying to reference an object created outside the class.  In that situation make sure your class is dynamic, for example:

dynamic public class YourClass extends MovieClip{

You can now add properties to YourClass instances from outside YourClass.

1120:Access of undefined property error xxxx

You either have a typo, you have forgotten that ActionScript is case sensitive or you have defined the variable somewhere but your reference is out of scope of the defined variable. Typically, the later occurs when you make a variable local to a function and then try and reference the variable outside that function.

For example,

function f():void{

      var thisVar:String = "hi";

}

trace(thisVar);

will trigger and 1120 error because thisVar is local to f() (as a consequence of prefixing its definition with the keyword var inside a function body.

To remedy, use the following (but you will need to call f() before thisVar has value "hi"):

var thisVar:String;

function f():void{

      thisVar = "hi";

}

trace(thisVar);

Check chapter 2, function scope for more information.

1120: Access of undefined property Mouse.

(import the needed class: flash.ui.Mouse):

import flash.ui.Mouse;

1151: A conflict exists with definition xxxx in namespace internal.

You have more than one of the following statements in the same scope:

var xxxx:SomeClass;

// and/or

var xxxx:SomeClass = new SomeClass();

To remedy, change all but the first  to:

xxxx = new SomeClass();

1178: Attempted access of inaccessible property xxxx through a reference with static type YYYY.

Variable xxxx typed private in class YYYY when should be protected, internal or public.

1180: Call to a possibly undefined method addFrameScript.

You have code (or even an empty space) on a timeline and your document class is extending the sprite class.  To remedy, extend movieclip or remove code from all timelines.  To find timeline code, use movie explorer and toggle only the show actionscript button.

1180: Call to a possibly undefined method xxxx

If you think you have defined that method, check for a typo. i.e., check your method's spelling and use copy and paste to eliminate typo issues.

Or, you have a path problem. To remedy, check your path and check the relevant (movieclip or class) scope section in chapter 2 to resolve path problems.

Or, if xxxx is a class name, you failed to define/save that class in the correct directory.  To remedy, save the needed class file and make sure the method xxxx is defined in your class.

Or, you are trying to use a method defined in a class that has not been imported. To remedy, import the needed class.

Or, you are trying to use a method xxxx that is not inherited by your class. For example, trying to use addEventListener in a custom class that does not extend a class with the addEventListener method will trigger a 1080 error.  To remedy, extend a class that has this method.

Or, you nested a named function. To remedy, un-nest it:

In actionscript, you can use named and anonymous functions.  A named function has the form:

function f1():void{

}

An anonymous function has the form:

var f1:Function = function():void{

}

In the code below, both f1() and f2() are named functions and f2() is nested in f1().

function f1():void{

      trace("f1");

      function f2():void{

            trace("f2");

      }

}

If you use this code, at no time will f2() be defined outside f1().  If you try and call f2() from outside f1(), no matter how many times you call f1(), you will generate an 1180 error:  call to a possibly undefined method.

To remedy, un-nest:

function f1():void{

}

function f2():void{

}

Alternatively, nest an anonymous function in a named function:

var f2:Function;

function f1():void {

      f2 = function():void{

      };

}

Or, nest two anonymous functions:

var f2:Function;

var f1:Function = function():void {

      f2 = function():void{

      };

}

Note f2 is declared outside f1.  That is required if you want to call f2 from outside the f1 function body.

If you tried:

function f1():void {

      var f2:Function = function():void{

            trace("f2");

      };

      f2();  // this will work

}

But, if you try:

function f1():void {

      var f2:Function = function():void{

            trace("f2");

      };

}

f1();

f2();

You will trigger an 1180: Call to a possibly undefined method f2 error.

You can expect the same error if you nest a named function in an anonymous function.  

You can nest name and anonymous functions if you only call the nested function from within the nesting function body.  For example, the following two snippets will not trigger an error.

Snippet 1:

function f1():void{

      trace(1);

      f2();

      function f2():void{

            trace(2);

      }

      f2();

}

f1();

Snippet 2:

var f1:Function=function():void{

      trace(1);

      f2();

      function f2():void{

            trace(2);

      }

      f2();

}

f1();

Nevertheless, while you can nest a named function in this situation without triggering an error, you should not.  There is no benefit to nesting a named function and, in addition to triggering 1180 errors, it makes your code less readable.

1203: No default constructor found in base class xxx.

Failure to call the superclass (or no constructor).  To remedy, either create a constructor or use super() in your already existing constructor.

SecurityError: Error #2000: No active security context.

The file you are trying to load does not exist.  You probably have a typo or a path problem. 

If your file loads when tested locally but triggers that error when test  online, look for case mis-matches. For example, trying to load file.SWF will load file.swf locally but not online.

TypeError: Error #2007: Parameter text must be non-null.

You are trying to assign undefined text to a TextField's text property. For example, the following will trigger this error:

var tf:TextField = new TextField();

var a:Array = [1,2];

var s:String;

  1. tf.text = s;

// and

  1. tf.text = a[2];

// will both trigger this error

Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

You have an incorrect path and/or file name.  First, double check your spelling and your paths.  Then make sure your load target's path is relative to the location of your swf's embedding html file's location, if you are testing by opening the html in a browser.  If you are testing in the Flash IDE or testing by opening the swf directly, the path should be relative to the swf.

2136: The SWF file file:///somepath/someswf.swf contains invalid data.

You are trying to use the "new" constructor with a document class.  To remedy, either remove that class from your document class or remove the "new" constructor applied to that class.

5000: The class 'xxx' must subclass 'yyy' since it is linked to a library symbol of that type.

Can occur because a previous error stoned the compiler triggering errors that do not exist.  But if it's the first (or only) error listed, your 'xxx' class must usually extend a MovieClip or SimpleButton.  Right click your library symbol, click properties and check the base class listed there.

5008: The name of definition 'Xxxx' does not reflect the location of this file. Please change the definition's name inside this file, or rename the file.

The file name and the class name must match.  For example,

package  {

      public class Xxxx {

            public function Xxxx(){

            }

      }    

}

must be saved as Xxxx.as (and case matters).

TOPICS
ActionScript

Views

18.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

Thank you Mr. Kglad, its really very helpful for the beginners.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2014 Mar 03, 2014

Copy link to clipboard

Copied

I some how have an error that ins't on here.

Error #1502: A script has executed for longer than the default timeout period of 15 seconds.

When i try and run the SWF the program crashes and i have to restart. I have run the debug and it picked up this error message. Here is my code, could you please help?

package  {

          import flash.display.MovieClip

          import flash.events.Event

          import flash.events.KeyboardEvent

 

          public class DocumentMain extends MovieClip

          {

                    public var _startMarker:StartMarker;

                    public var _player:Player;

                    public var _boundaries:Boundaries;

 

                    private var _vx:Number;

                    private var _vy:Number;

 

                    public function DocumentMain():void

                    {

                              // Assign default values

                              _startMarker.visible = false;

                              _vx = 0;

                              _vy = 0;

 

                              // Set focus for keyboard unput

                              stage.focus = stage;

 

                              // Add event listeners

                              this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

                              stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);

                              stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

                    }

 

                    private function enterFrameHandler(e:Event):void

                    {

                              // Gravitate the player

                              _vy += 2;

 

                              // Move the player

                              _player.x += _vx;

                              _player.y += _vy;

 

                              //Process collisions

                              processCollisions();

 

                              //Scroll the stage

                              scrollStage();

                    }

 

 

                    private function keyDownHandler(e:KeyboardEvent):void

                    {

                    }

 

                    private function keyUpHandler(e:KeyboardEvent):void

                    {

                    }

 

                    private function processCollisions():void

                    {

                              // When player is falling

                              if (_vy > 0)

                              {

                                        // Respawn if player fell off the stage

                                        if (_player.y > stage.stageHeight)

                                        {

                                                  _player.x = _startMarker.x;

                                                  _player.y = _startMarker.y;

                                                  _boundaries.x = 0;

                                                  _boundaries.y = 0;

                                                  _vy = 0;

                                        }

                                        //Otherwise, process collisions with boundaries

                                        else

                                        {

                                                  var collision:Boolean = false;

 

                                                  if (_boundaries.hitTestPoint(_player.x, _player.y, true))

                                                  {

                                                            collision = true;

                                                  }

 

                                                  if (collision)

                                                  {

                                                            while (collision)

                                                            {

                                                                      _player.y -+ 0.5;

 

                                                                      collision = false;

 

                                                                      //if (_boundaries.hitTestPoint(_player.x, _player.y, true))

                                                                      {

                                                                      collision = true;

                                                                      }

                                                            }

 

                                                            _vy = 0;

                                                  }

 

                                        }

 

                              }

                    }

 

                    private function scrollStage():void

                    {

                    }

 

          }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2015 May 11, 2015

Copy link to clipboard

Copied

LATEST

for anybody else checking this thread, DO NOT POST HERE.  noone checks it.

post in one of the main flash forums (eg, actionscript 3:  ActionScript 3

and for anybody checking the previous message, that error is always caused by a loop (for, while, do), or circular functions that executes for longer than the script time limit (file>publish setting>script time limit).

so that can happen when processing a lot of data, but often it's because an end-condition will never be met in the run-away loop like the previous poster's code where:

while(collision) loop never ends.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines