Fixing ActionScript Errors

Fixing ActionScript errors is always a difficult task for new developers.  The cryptic language that Flash likes to communicate back to the user with is not always the easiest to understand.  A typical ActionScript error in Flash Professional will look something like this:

Implicit coercion?  It’s pretty obvious why people struggle learning ActionScript.  There are essentially two parts to an ActionScript Error:  The location (on the left) and the description (on the right).  Double-clicking on an error takes you to the line the error occurred (most of the time).  Occasionally it will take you to a different location unrelated to the error.

Let’s look at some of the most common error message, what they mean, and how to fix them.  If you’re interested, a list of all the possible ActionScript errors can be found in the help files here.  Also, here’s a nice search site where you can type in the error code and see a description.

1021: Duplicate function definition.

This one is pretty easy.  It’s saying you have the same function declared two times in your code (as pictured below).

function doSomething():void{
 
}
function doSomething():void{
 
}

Solution: Delete or rename one of the functions.

1046 Type was not found or was not a compile-time constant: [Something].

This error shows up whenever you have a variable defined in your code and Flash doesn’t know the type (what comes after the colon).

//"Number" is spelled wrong and would cause an error
var totalScore:Nummber;
 
//Same error occurs with this line, however "Tween" is spelled
//correctly. In this case you need an import statement
var animation:Tween;

Solutions: Fix the spelling or add an import statement

1051 Return value must be undefined.

You have a function with a return type of  ”void”  that is returning a value.

function doSomething():void{
	var total:Number = 10;
	return total;
}

Solutions: Either change the void to match the type of what you’re returning or remove the return statement

1061 Call to a possibly undefined method [Something] through a reference with static type [Something].

Firstly, method is another name for function. This error means you are calling a function that doesn’t exist. This might be because the object you are working with doesn’t have that function or because you spelled the function wrong.

//submit_btn is a Button on the stage
//pages_mc is a MovieClip on the stage
 
//This line triggers the error because Button objects don't have
//a "gotoAndStop" function
submit_btn.gotoAndStop(3);
 
//This line triggers the error because "gotoAndStop"
//is spelled wrong.
pages_mc.gotoandStop(3);

Solution: Spell the function correctly or makes sure you are calling the function on the correct object.

1067 Implicit coercion of a value of type [Something] to an unrelated type [Something].

This error means you are setting two things equal to each other and they are not the same type.  In other words, an Apple does not equal an Orange.  In the case of Flash, a String does not equal a Number or a MovieClip does not equal a button.

//This line will give you an error
//Implicit coercion of a value of type String to an
//unreated type Number
var title:Number = "flash";

The count variable was declared as a Number so you can only set it equal to a number (5, 100, etc).  The word “flash” is considered a String (text).

Solution: Make sure your types match.  If you are setting a Number variable on the left side of the equal sign, the thing on the right side needs to be a number too.

1083 Syntax error: [Something] is unexpected.

This error can be the product of a lot of different errors.  The [Something] could be a semi-colon, curly brace, or any other character.  In most cases, this error shows up because you need to remove a character.  Here are some examples of line that would cause this error:

//You need to remove the extra plus
var count:int = 5 + 23 + ;
 
//Remove extra quotes
var title:String = "flash" ""
 
//Remove the extra curly brace
function doSomething():void
{
 
}
}

Solution:  Add/remove the characters that are causing the error.

1084 Syntax error: expecting [Something] before [Something].

This error, most of the time, let’s you know what you are missing.  For example, “Expecting a right brace before end of program”.  This means you need a “}” before the last line of code:

//Expecting right brace:  The function is
//missing the closing }
function doSomething()
{
 
//Expecting right paren: Missing a closing }
//after the 5
gotoAndStop(5

Solution: Identify what you are missing and add it in the appropriate place.

1094/1095 Syntax error: A string literal must be terminated before the line break.

Any error about a “string literal” normally means you are missing a quote.  Strings are always wrapped in quotes like this: “flash”.  If you forget a closing quote, you’ll see an error.  You’ll also see the green string color “bleed” through the rest of you document.

//This line is missing a " after the word app
var title:String = "Welcome to my app
myField.text = title;

Solution:  Add a closing ” at the end of the String;

1120 Access of undefined property [Something].

This error pops up if you have a variable spelled wrong or are trying to use something that doesn’t exist.  Most of the time it’s related to spelling a variable or instance name wrong.

var title:String;
//We'll get an error on this line because it
//doesn't match the variable name
ttle = "flash";
 
//There's a MovieClip on the stage named pages_mc
//If you type the name wrong in your code, you'll see
//an error
pg_mc.gotoAndPlay(2);

Solution: Make sure you are spelling the instance name or variable name correclty

1126 Function does not have a body.

99 times out of 100 this error is due to a rogue semi-colon at the end of a function declaration.  This error is due to Flash not seeing the curly braces (the body) of a function.

//Remove the ; to remove the error
function doSomething():void;
{
 
}

Solution: Remove any semi-colons in the function line

1136/1137 Incorrect number of arguments. Expected [Some Number].

If your are calling a function and not passing the right amount of parameters (either too many or too few), you’ll see this error.

//This line should have no parementers:  i.e. stop();
stop(3);
//This line should have one parameter: i.e. gotoAndStop(3);
gotoAndStop();

Solution: Add/remove parameters so the correct amount are passed to the function

1151 A conflict exists with definition [Something] in namespace [Something].

In this case, you have a two or more variable declared with the same name.  This applies to function too.

var count:Number = 0;
 
//more code
 
var count:Number = 0;

Solution: Rename one of the variables so there is not a duplicate.

1170 Function does not return a value.

If you create a function and give it a return type, there must be a return line in it.  If you function isn’t supposed to return a value, the return type must be void.  In the following example, the return statement is commented out and would cause an error.  Uncommenting it or changing the :Number in the function line would fix the error.

function getTotal():Number
{
	var total:Number = 20;
	//return total;
}

Solution: Add a return statement or change the return type to void

Still quiet here.sas

Leave a Response

Why ask?