Common Flash Compiler Errors: #1046
This error shows the following in the Compiler Errors window:
1046: Type was not found or was not a compile-time constant: [Class name].
Quick Answer and Solution
Where I have “[Class name]” above you will have any number of names listed, for example it may say Event, Sprite, TextField, etc. What this means is you are using a piece of code that utilizes a class (typically seen as files with a “.as” extension) that you have not “imported” so that your code knows where to find it. To fix this problem perform the following:
- Open a web browser and navigate to Google.
- Enter the search “[class name] actionscript 3 site:livedocs.adobe.com” (replacing [class name] with whatever the class name is in the error message, such as TextField, MouseEvent, URLLoader, etc.). For example, “Event actionscript 3 site:livedocs.adobe.com”
- Look for a search result that lists the class in a format of a series of words with dots between them, probably will be the top result. Examples include:
- flash.events.Event
- flash.display.Sprite
- fl.transitions.Tween
- flash.geom.Rectangle
This is the path to the class, which you can use to import the class into your code.
- Without clicking on the search result, copy the class name as it appears in the previous step.
- Return to Flash and double-click the error message.
- Scroll to the top of the code area. Type “import” and paste the path to the class. For example,
import flash.events.Event;
If you are using code on the Timeline, this can be placed at the top of the Actions panel. If you have written a class file that is referencing another class, this code appears between the package { curly brace, and class declaration, public class MyClass.
For example,
package { // class import statements appear here import flash.display.MovieClip; public class Main extends MovieClip { public function Main() { } } }
Technical Overview
A class file is an external text file that contains variables and functions (known as properties and methods in the object-oriented programming context), essentially this means class files are self-contained blocks of code that contain code related to a particular task. To access these variables and functions within your own block of code the class file needs to be imported. If your code contains any references to a class file that has either: (a) not been imported, or (b) is not within the same folder as your .fla or .as files, then a #1046 error will be thrown. For example, suppose you have the following class file declared for a button:
package { import flash.display.MovieClip; public class MyButton extends MovieClip { public function MyButton() { this.addEventListener( MouseEvent.CLICK , _clicked ); } private function _clicked( evt:MouseEvent ) : void { // button was clicked! } } }
Testing this code would produce the following error:
1046: Type was not found or was not a compile-time constant: MouseEvent.
With the source listed as…
private function _clicked( evt:MouseEvent ) : void
This is because the class MouseEvent is referenced in the code, but is not imported at the top of the class file. The fix is simple and looks like this:
package { import flash.display.MovieClip; // import the MouseEvent class import flash.events.MouseEvent; public class MyButton extends MovieClip { public function MyButton() { this.addEventListener( MouseEvent.CLICK , _clicked ); } private function _clicked( evt:MouseEvent ) : void { // button was clicked! } } }
Typically if you are a beginning ActionScripter, you will run into this error when referencing classes created by Adobe. However, as you become more advanced in your scripting abilities you may place your own custom class files in “packages” that would then need to be imported using the same above process. In case you are wondering what the stuff is before the actual class name, such as “flash.display” and “flash.events,” this is the “package” that class resides in, which is essentially the folders the class file resides in on disk. For example, suppose I created a class called “MyButton” and placed it in the package “com.anselmbradford.” This class would appear in a text file called “MyButton.as” that would be in a folder called “anselmbradford” that would itself be in a folder called “com.” The class file would look like:
package com.anselmbradford { import flash.display.MovieClip; public class MyButton extends MovieClip { public function MyButton() { } } }
To import this class file into another class file I would place the “com” folder (containing the class file two levels in) in the same directory as my .fla or .as file that I wanted to import this class into. I would then import it using the syntax shown previously. For example:
package { import flash.display.MovieClip; // class is imported import com.anselmbradford.MyButton; public class Main extends MovieClip { public function Main() { // class is referenced in code, so must be imported var button:MyButton = new MyButton(); } } }
Note: Whole sets of class files that are within the same package can be imported using the “*” wildcard operator. For example, flash.events.Event, and flash.events.MouseEvent, both reside in the flash.events package. Instead of having two lines to import both of these classes, you can have import flash.events.*;, which will import all the necessary classes from the flash.events package.
UPDATE October 4, 2009:This error will also occur if you have a symbol on your stage that has an instance name that is the same as a class name associated with the symbol. Check the Library panel, under the Linkages column, does any of your symbols have a name next to “Export:” that is the same as the instance name in the Properties panel of one of those symbols on the stage?


May 2nd, 2010 at 12:49 pm
Just wanted to say thanks for writing this article! I’m definitely new to AS 3, and this error has been bugging me for a while. What I like specifically about this article than the others I’ve read regarding this error is the attention to detail and screenshots. Keep up the great work here!
July 27th, 2010 at 12:25 pm
Hi there,
I having been dipping in and out of AS3 for the last year and it always infuriates me, for example when i even try and use the examples in the flash help its splits out this 1046 error
1046: Type was not found or was not a compile-time constant: RadioButtonGroup.
July 27th, 2010 at 11:23 pm
Stefan,
Adding “import mx.controls.RadioButtonGroup;” at the top of your code should help!
July 28th, 2010 at 3:23 am
Hey Ans, thanks for the speedy response, i appreciate it! Unfortunately it didn’t do the trick though..
SO how does that work, are the mx.controls and fl.controls different? Is it just the pre CS version or something or am i way off the mark?
July 28th, 2010 at 4:17 am
Oops, my mistake, I meant “import fl.controls.RadioButtonGroup;” the mx package is for Flex, fl is for Flash. Are you using an older version of Flash? The fl package was introduced relatively recently, in CS4 if my memory serves me correctly. These are ActionScript code libraries (classes) you’re importing, so if you’re using an older version of Flash they won’t exist, and hence won’t be imported, and you’ll get a #1046 I believe.
October 13th, 2010 at 6:05 pm
i’m getting this error when creating an instance of the Tween class. i have other AS-generated Tweens in my SWF that work so i know i’m importing the class properly. i’m not using any custom classes and i’m not calling objects from the library(only objects already onstage) so i’m not setting the export for AS on any of my library objects. i understand that there are nuances to my SWF that make it difficult to troubleshoot in this fashion, but i wonder if there are any other reasons you know of why this might happen.
this.casey_btn.addEventListener(MouseEvent.MOUSE_UP, playCasey);
function playCasey(evt:MouseEvent):void {
var bioPaneTween:Tween = new Tween(this.bioPane, “x”, Regular.easeOut, 100, 370, 20, false);
}
casey_btn:Button and bioPane:MovieClip are already named and on the stage.
October 13th, 2010 at 9:18 pm
Hmm, I don’t immediately see an issue from what you’ve supplied. The error looks like you’re trying to create an instance named casey_btn and bioPane when these are already named in instances through the Properties panel (just a guess). Try putting stop(); above the code you provided. Perhaps the code is looping and the second time round it’s having issues.
January 19th, 2011 at 7:20 am
1046 type was not found or was not a compile-time constant:tween
——————————————————————————-
My code is also suffering with same problem, I have imported all the things which is required(imported tween and other classes also) but still there is same error
How could i solve this problem please help me
January 19th, 2011 at 3:14 pm
Mohsin,
Check the capitalization on “tween”, I suspect it should be “Tween” in your code.
Cheers!