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

The class used as a type declaration is either unknown or is an expression that could have different values at run time. Check that you are importing the correct class and that its package location has not changed. Also, check that the package that contains the code (not the imported class) is defined correctly (for example, make sure to use proper ActionScript 3.0 package syntax, and not ActionScript 2.0 syntax).

The error can also occur if the class being referenced is not defined in a namespace that is in use or is not defined as public:

public class Foo{}

Description:
One reason you will get this error is if you have an object on the stage with the same name as an object in your library. So if you are trying to dynamically add a movieClip from your library that has a Class name (see image below) that is the same as the name of an instance on the stage it will give you this error. What happens when you add a class name in the library is that Flash (in this case) will create a class around that object. When you have an instance on the stage that has this same name Flash doesn’t know how to handle it because the Class was not properly instantiated.

Fix 1:
Remove the instance from the stage, change the name of the instance or remove the Class linkage in your library.

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

Fix 2:

Import, Import, Import. Another common reason that you will get this error is because you have not imported everything you are including in your movieClip. For example if you are using textFields inside your movieClip you need to include the following line of code:

Good Code:

    import flash.text.TextField;

By importing the TextField object the compiler now knows what to do with that textField inside your movieClip. This will eliminate another version of this error - ’1046: Type was not found or was not a compile-time constant: TextField’.

About Judah

Please note in the comments if this has helped you or not.
This entry was posted in Compiler. Bookmark the permalink.

26 Responses to 1046 Type was not found or was not a compile-time constant: _.

  1. nicii says:

    hey, ive been trying to get over a similar error for a day or 2 and its really frustrating.
    basically i have a class for my flash file, a method showThink takes in a movieclip and sets its visible property to true.
    squareA is a symbol, squareAmc is its instance

    package {
    import flash.display.MovieClip;
    import mx.flash.UIMovieClip;

    public class sands extends UIMovieClip
    {
    function sands()
    {
    squareAmc.visible=false;
    }

    public function showThink(county:MovieClip):void
    {
    county.visible = true;
    }
    }
    }

    in flex when i call on a button click=”idX.showThink(squareA);”

    first i was getting “Implicit coercion of a value of type Class to an unrelated type flash.display:MovieClip.”

    then when i changed it to “idX.showThink(squareAmc)” //instance name
    i get “Access of undefined property squareAmc”

    ive tried as MovieClip and ive tried changing class name for SquareA,
    do i need to define instance squareAmc dynamically? if so how?

    thank you in advance :)

  2. Daniel says:

    Hey, just wanted to leave a thanks for the bit above regarding the 1046 error. I am working on a collaborative project across a few offices and wasn’t aware they had added graphics to the stage statically.

    The bit about the compiled class not being able to share a name with something on the stage was a great help.

  3. Tricky says:

    Don’t forget to make sure you’ve declared your class public if you’re trying to access a class from outside of its package. By default flash declares classes as internal….

    package
    {
    public class
    {}
    }

    instead of

    package
    {
    class
    {}
    }

  4. Curtis J. Morley says:

    Great tip Tricky. It isn’t always obvious that by not declaring the class public that it has a default of internal.

    Thanks,
    Curtis J. Morley

  5. Shawn says:

    I created a movie clip that is nothing more than a graphic and converted it to a movie clip and tried to publish into Flex 2. I got a bunch of these 1046 errors with no source. I converted my movie clip into a flex component. Could this be causing all the errors. I got like 6:
    1046: Type was not found or was not a compile-time constant: Producer.
    1046: Type was not found or was not a compile-time constant: Consumer.
    1046: Type was not found or was not a compile-time constant: WebService.
    1046: Type was not found or was not a compile-time constant: RemoteObject.
    1046: Type was not found or was not a compile-time constant: HTTPService.

    None of these have anything to do with my flash and from what I can tell.. my Flex either

  6. Curtis J. Morley says:

    Shawn,

    For some reason Flash/Flex is trying to compile these classes and is finding a conflict. It seems that the first two are custom classes that you either wrote or more likely it is from a library symbol that has a class definition and a Base Class definition (see image above).

    If you are in Flash try opening the ‘Movie Explorer’ (Alt+F3 or Window >> Movie Explorer) and do a search for Consumer or Producer with all of the options set to show. If you are Flex open the ‘File Search’ dialog (Ctrl + Shift + F) and do a search for the same terms. It may be an import from another class or something that you wouldn’t think is being imported but is.

    Let me know how this works for you and as always Happy Flashing.

  7. ernest says:

    trying to script a preloader in flash 8 actionscript 3.0, tutorial that iam followin is here http://learn005.com/podcasts/flash/preloader.mp4 i have the cose just like he says but i keep getting the 1046 error this.onEnterFrame = function():Void {

  8. stan says:

    I’m having the same problem as Ernest. What bugs me is that I did this preloader tutorial and was successful the first time around. The second and third time I tried it, I received the 1046 error with Void. Don’t know what to do.

  9. Curtis J. Morley says:

    Ernest and Stan,

    You may want to consider another way of writing this preloader especially if you are using AS3. ActionScript now has an event model that standardizes the way all events are handled. It is really nice even though it does add some overhead to the code. I will post a lesson here on my blog to show how to make an ActionScript 3 preloader.

    Thanks,
    Curtis

  10. Carroll Altman says:

    Curtis,

    I am new to ActionScript 3 and I am having problems with this exercise taken directly from the Adobe documentation for programming with ActionScript 3. I keep getting 1046 and 1083 errors. I am confused because you would think that these people would test this out before releasing it to the public. I am not sure what is missing here. I tried to use the #include statment and I got an error. I am not sure how to have the .fla file access the .as file. This package thing is a complete mystery to me and I am not sure where to go to resolve the issue. I am using a Mac if that makes a difference. Can you help me out? I have included the content from the Programming Action Script 3 that Adobe provides. It is just a few paragraphs with the code and the instructions included. It would seem to me that Adobe should pay more attention to their quality control. If the documentation is inaccurate how are we supposed to learn how to use the product?

    Creating the HelloWorld project and the Greeter class
    The design statement for the Hello World application said that its code should be easy to reuse. With this goal in mind, the application uses a single object-oriented class, named Greeter, which is used from within an application that you create in Flex Builder or the Flash authoring tool.

    To create the Greeter class in the Flash authoring tool:
    In the Flash authoring tool, select File > New.
    In the New Document dialog box, select ActionScript file, and click OK.
    A new ActionScript editing window is displayed.

    Select File > Save. Select a folder to contain your application, name the ActionScript file Greeter.as, and then click OK.
    Continue with Adding code to the Greeter class.

    Adding code to the Greeter class
    The Greeter class defines an object, Greeter, that you will be able to use in your HelloWorld application.

    To add code to the Greeter class:
    Type the following code into the new file:package
    {
    public class Greeter
    {
    public function sayHello():String
    {
    var greeting:String;
    greeting = “Hello World!”;
    return greeting;
    }
    }
    }

    The Greeter class includes a single sayHello() method, which returns a string that says “Hello World!”.

    Select File > Save to save this ActionScript file.
    The Greeter class is now ready to be used in a Flash or Flex application.

    Creating an application that uses your ActionScript code
    The Greeter class that you have built defines a self-contained set of software functions, but it does not represent a complete application. To use the class, you need to create a Flash document or Flex application.

    The HelloWorld application creates an new instance of the Greeter class. Here’s how to attach the Greeter class to your application.

    To create an ActionScript application using the Flash authoring tool:
    Select File > New.
    In the New Document dialog box, select Flash Document, and click OK.
    A new Flash window is displayed.

    Select File > Save. Select the same folder that contains the Greeter.as class file, name the Flash document HelloWorld.fla, and click OK.
    In the Flash Tools palette, select the Text tool, and drag across the Stage to define a new text field, approximately 300 pixels wide and 100 pixels high.
    In the Properties window, with the text field still selected on the Stage, set the text type to Dynamic Text and type mainText as the instance name of the text field.
    Click the first frame of the main timeline.
    In the Actions panel, type the following script: var myGreeter:Greeter = new Greeter();
    mainText.text = myGreeter.sayHello();

    Save the file.
    Continue with Publishing and testing your ActionScript application.

    Publishing and testing your ActionScript application
    Software development is an iterative process. You write some code, try to compile it, and edit the code until it compiles cleanly. You run the compiled application, test it to see if it fulfills the intended design, and if it doesn’t, you edit the code again until it does. The Flash and Flex Builder development environments offer a number of ways to publish, test, and debug your applications.

    Here are the basic steps for testing the HelloWorld application in each environment.

    To publish and test an ActionScript application using the Flash authoring tool:
    Publish your application and watch for compilation errors. In the Flash authoring tool, select Control > Test Movie to compile your ActionScript code and run the HelloWorld application.
    If any errors or warnings are displayed in the Output window when you test your application, fix the causes of these errors in the HelloWorld.fla or HelloWorld.as files, and then try testing the application again.
    If there are no compilation errors, you will see a Flash Player window showing the Hello World application.
    You have just created a simple but complete object-oriented application that uses ActionScript 3.0. Continue with Enhancing the HelloWorld application.

  11. Curtis J. Morley says:

    Carroll,

    The issue arises because the .FLA doesn’t know where the .AS is. This could either be because you haven’t saved the file yet, or you haven’t saved the file in the same location. I get the same two errors using the same “Hello World” example in the Flash/Flex docs as you when I haven’t saved the file or if I save it in a separate location from the .as file. This is solved as soon as the .fla is in the same folder as the .as file. If you want the .as file to be somewhere else that works also. The only thing that you will need to do is to use an import statement and target the file correctly.

    Glad that you are joining the Flash community. Thanks Carroll and Happy Flashing.

    Curtis J. Morley

  12. Carroll Altman says:

    I left a comment here yesterday with a question. Where did it go?

  13. Curtis J Morley says:

    Carroll,

    Comments are moderated so that I don’t get flooded with inappropriate spam. Thanks again for the very detailed comment.
    Happy Flashing,

    Curtis J Morley

  14. Aral Balkan says:

    And, finally, check that you’ve spelled everything correctly in your package singature or you might get this error :)

  15. Aral Balkan says:

    LOL, or “package _signature_” even! (’nuff said!) :)

  16. Curtis J Morley says:

    LOL. Good to hear from you Aral. Great point.

  17. Xaviar says:

    i have been trying to figure this error message for about three days. I keep getting this error message and error message 1120. which i have no clue how to fix because they seem to contradict themselves.

    if you have any advise whatsoever i would greatly appreciate that.

  18. Curtis J. Morley says:

    Xavier,

    Check your instance names. If you are getting this accompanied with AS3 Error 1120 I highly suggest that you check your instance names and your class name in your linkage in the library.

    Let me know how that works.

    Thanks,

    Curtis J. Morley

  19. Thilo says:

    Thanks so much for your help here !
    I followed all your advice thorroughly but could not find a way to build a tutorial project.
    In the end I found out, that People with a Flexbuilder can simply click on:
    PROJECT – CLEAN UP – ALL PROJECTS,
    and many error messages and also this Eror was gone !!!
    Next time before panicing, try this feature – it might sve you hours ! ;-)

  20. Curtis J. Morley says:

    Thilo,

    Great place to put this comment. This is thing that everyone should do before manual removal of hair. Sometimes the Eclipse framework gets hung up and you have to CLEAN the project before everything will build properly. Thanks for posting this comment. I know it will help many.

    Curtis J. Morley

  21. Knight Chat X says:

    I got this error too and adding:
    import flash.text.TextField;

    Seemed to solve the problem when I added it to the import section of the package. I don’t remember having that error before when adding text field’s.

    But it works fine now.

  22. Balaji says:

    Hi
    I have a problem in Creating Flex Component to Flash CS3,

    1.I had created the Flex component in Flex, and the component is working Flex 3.

    2. The same component which has been created has to work in the Flash CS3

    Please let me know how to get worked in the Flash CS3

    //Here is the code
    package myComponents
    {
    // asAdvanced/myComponents/DeleteTextArea.as
    import mx.controls.Button;

    public class BlueButton extends Button {

    public function BlueButton() {
    super();
    }

    override protected function measure():void {
    super.measure();

    //Specifies the default height and width of the component, in pixels
    measuredWidth=200;
    measuredHeight=80;

    //Specifies the default minimum height and minimum width of the component,
    // in pixels. Flex cannot set the size of a component smaller than
    // its specified minimum size.
    measuredMinWidth=500;
    measuredMinHeight=25;

    }
    }
    }

  23. Dushan says:

    Hello i am new with AC 3.0 and i am going trough adobe’s help last several days and i came to the point of doing Example with creating basic application from adobe’s help.

    My problem or more the part that i don’t understand is that, when making Greeter class that goes like :

    package
    {
    public class Greeter
    {
    public function sayHello():String
    {
    var greeting:String;
    greeting = “Hello World!”;
    return greeting;
    }
    }
    }

    below it there is a comment that says: “The Greeter class includes a single sayHello() method, which returns a string that says “Hello” to the user name that is given.”

    but when i write the code:

    var myGreeter:Greeter = new Greeter();
    mainText.text = myGreeter.sayHello(“Bob”);

    i get the compailer error saying “1137:Incorect number of arguments etc.”

    Now when i delete the “Bob” from pharentesis it does what it seems it should write the “Hello World!” and it works but in the adobe’s help it says:”If there are no compilation errors, you will see a Flash Player window showing the Hello World application. The “Hello, Bob” text is displayed.”

    My question is, what do i need to do, to make it write HELLO BOB rather then HELLO WORLD and not get the 1137 error?

    Thanks.

  24. admin says:

    Create a parameter for the method,

    public function sayHello(something:String):String
    {
    var greeting:String;
    greeting = “Hello ” + something;
    return greeting;
    }

  25. prem says:

    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.*;
    import flash.geom.Matrix;
    import flash.events.Event;
    import flash.display.GraphicsBitmapFill;
    import flash.display.DisplayObject;
    import flash.display.DisplayObjectContainer;
    import flash.display.GraphicsBitmapFill;
    stop();
    /* Stop at This Frame
    The Flash timeline will stop/pause at the frame where you insert this code.
    Can also be used to stop/pause the timeline of movieclips.
    */

    /* Click to Position an Object
    Moves the specified symbol instance to the x-coordinate and y-coordinate you specify.

    Instructions:
    1. Replace the value 200 with the x-coordinate
    where you want to position the object.
    2. Replace the value 100 with the y-coordinate where you want to position the object.
    */

    /* Mouse Click Event
    Clicking on the specified symbol instance executes a function in which you can add your own custom code.

    Instructions:
    1. Add your custom code on a new line after the line that says “// Start your custom code” below.
    The code will execute when the symbol instance is clicked.
    */
    am getting error
    Scene 1 1046: Type was not found or was not a compile-time constant: sheet1.
    Scene 1 1046: Type was not found or was not a compile-time constant: tex_mc.

    Object(this).tex_mc.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);

    function fl_MouseClickHandler(event:MouseEvent):void
    {

    Sprite; var pic:Bitmap; // a Bitmap (reference or instantiate yourself)
    var bmd:BitmapData=pic.bitmapData; //get BitmapData from Bitmap
    var bg:Sprite=new Sprite();
    bg.graphics.clear(); bg.graphics.beginBitmapFill(bmd);
    bg.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
    addChild(bg);
    }

    can anyone help please

  26. prem says:
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.*;
    import flash.geom.Matrix;
    import flash.events.Event;
    import flash.display.GraphicsBitmapFill;
    import flash.display.DisplayObject;
    import flash.display.DisplayObjectContainer;
    import flash.display.GraphicsBitmapFill;
    stop();
    /* Stop at This Frame
    The Flash timeline will stop/pause at the frame where you insert this code.
    Can also be used to stop/pause the timeline of movieclips.
    */
    
    
    
    /* Click to Position an Object
    Moves the specified symbol instance to the x-coordinate and y-coordinate you specify.
    
    Instructions:
    1. Replace the value 200 with the x-coordinate
       where you want to position the object.
    2. Replace the value 100 with the y-coordinate where you want to position the object.
    */
    
    /* Mouse Click Event
    Clicking on the specified symbol instance executes a function in which you can add your own custom code.
    
    Instructions:
    1. Add your custom code on a new line after the line that says "// Start your custom code" below.
    The code will execute when the symbol instance is clicked.
    */
    am getting error 
    Scene 1	1046: Type was not found or was not a compile-time constant: sheet1.
    Scene 1	1046: Type was not found or was not a compile-time constant: tex_mc.
    
    Object(this).tex_mc.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
    
    function fl_MouseClickHandler(event:MouseEvent):void
    {
    	
    	Sprite; var pic:Bitmap; // a Bitmap (reference or instantiate yourself)
    	var bmd:BitmapData=pic.bitmapData; //get BitmapData from Bitmap
    	var bg:Sprite=new Sprite();
    	bg.graphics.clear(); bg.graphics.beginBitmapFill(bmd);
    	bg.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
    	addChild(bg);
    }
    
    can anyone help please
    

Leave a Reply

Your email address will not be published. Required fields are marked *

Highlight your code before posting code:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="">