06.20.07

Flash CS3 / Flex 2 AS3 Error #1046

Posted in errors, Flash, Flex at 7:28 pm by Curtis J. Morley

Error #1046: Type was not found or was not a compile-time constant: Name.

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.

AS3 Error 1046 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:

AS3 Error 1046 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'.

Update:

AS3 Error 1046 Fix 3:

This error will also show up if you are trying to instantiate a library object with an instance name that is the same as the AS Linkage in your library. In other words, you can't call it the same name. Look at the image for the Linkage name and then take a look at the code examples. The red code below shows that the same name is being used.

AS3 1046 Error - Library AS Linkage Name

Bad Code:

var TTA:TTA = new TTA();

Good Code:

var thirdAlternative:TTA = new TTA();

 

And now you know three ways to resolve ActionScript Error #1046: Type was not found or was not a compile-time constant:
As always Happy Flashing!

56 Comments »

  1. nicii said,

    July 23, 2007 at 1:38 pm

    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 said,

    November 2, 2007 at 4:59 pm

    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 said,

    November 15, 2007 at 2:58 pm

    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 said,

    November 15, 2007 at 6:07 pm

    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 said,

    December 13, 2007 at 5:24 pm

    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 said,

    December 18, 2007 at 5:26 pm

    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 said,

    January 10, 2008 at 8:43 pm

    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 said,

    February 7, 2008 at 1:16 am

    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 said,

    February 7, 2008 at 8:36 pm

    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 said,

    February 7, 2008 at 10:02 pm

    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 said,

    February 7, 2008 at 10:03 pm

    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 said,

    February 8, 2008 at 7:17 pm

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

  13. Curtis J. Morley said,

    February 8, 2008 at 8:06 pm

    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 said,

    April 16, 2008 at 3:08 am

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

  15. Aral Balkan said,

    April 16, 2008 at 3:08 am

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

  16. Curtis J. Morley said,

    April 21, 2008 at 12:38 pm

    LOL. Good to hear from you Aral. Great point.
    Snpilleg is iprnmoatt..or is it?

  17. Xavier said,

    May 7, 2008 at 8:32 am

    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 said,

    May 7, 2008 at 10:52 am

    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 said,

    May 26, 2008 at 7:21 pm

    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 said,

    May 26, 2008 at 9:44 pm

    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. curtismorley.com » Search Engine Optimization Example said,

    June 2, 2008 at 4:42 pm

    [...] ActionScript 3 Error – #2 on Google [...]

  22. Common ActionScript 3 Errors and Explanations | Jake Rutter - XHTML/CSS Developer said,

    June 11, 2008 at 8:29 am

    [...] Morley has come up with a great explanation as to what this actually means, you can read about it here. Share and Enjoy: These icons link to social bookmarking sites where readers can share and [...]

  23. Knight Chat X said,

    June 23, 2008 at 3:51 am

    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.

  24. Balaji said,

    July 13, 2008 at 10:47 pm

    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;

    }
    }
    }

  25. curtismorley.com » AS3 Error #1051: Return value must be undefined. said,

    August 20, 2008 at 12:55 pm

    [...] uint, Number, Array, Bitmap, etc…)Flash Warning 3590 (If you specified a return type of Boolean)Flash Error 1046 (If you specified a return type of [...]

  26. Eric Oliver said,

    September 29, 2008 at 1:14 am

    So small an error, so simple a solution, and yet it was so elusive until this post. Awesome and thanks much!

    –eric

  27. DJJaxe said,

    October 8, 2008 at 3:24 am

    hi all so i have a problem with flex3.* i load wimas3(aim’s flex/flash library) and i get an error on the BuddyListEvent ill give u the code from that package its quiet large…:
    /*
    Copyright (c) 2008 AOL LLC
    All rights reserved.

    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    Neither the name of the AOL LCC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

    package com.aol.api.wim.events
    {
    import com.aol.api.wim.data.BuddyList;
    import com.aol.api.wim.data.Group;
    import com.aol.api.wim.data.User;

    import flash.events.Event;

    /**
    * The BuddyListEvent is fired when either groups or users are
    * added, removed, or moved on the buddy list.
    */

    public class BuddyListEvent extends Event
    {
    /**
    * This event fires when a full buddy list is received.
    */
    public static const LIST_RECEIVED:String = “buddyListReceived”;

    /**
    * This event is fired before a buddy is added to the buddy list.
    */
    public static const BUDDY_ADDING:String = “buddyAdding”;
    /**
    * The value for the type property of a buddy added event object.
    */
    public static const BUDDY_ADD_RESULT:String = “buddyAddResult”;
    /**
    * This event is fired before a buddy is removed from the buddy list.
    */
    public static const BUDDY_REMOVING:String = “buddyRemoving”;
    /**
    * The value for the type property of a buddy removed event object.
    */
    public static const BUDDY_REMOVE_RESULT:String = “buddyRemoved”;

    /**
    * The value for the type property of a group added event object.
    */
    public static const GROUP_ADD_RESULT:String = “groupAddResult”;
    /**
    * The value for the type property of a group removed event object.
    */
    public static const GROUP_REMOVE_RESULT:String = “groupRemoveResult”;

    /**
    * The buddy associated with the event. Only valid for buddy added, buddy moved, and buddy removed events.
    * This is null for group events and the LIST_RECEIVED event.
    *
    * For the BUDDY_ADDING event, the only property that is set on the user object is the aimId.
    */
    public var buddy:User;

    /**
    * The group associated with the event. If it is a buddy related event, it represents that buddy’s group.
    * This is null for the LIST_RECEIVED event.
    */
    public var group:Group;

    /**
    * @private
    * The personal message associated with the add buddy call. Only for ICQ.
    */
    public var authorizationMsg:String;

    /**
    * @private
    * Pre-authorized to allow the new buddy to add self into his/her buddylist. Only for ICQ.
    */
    public var preAuthorized:Boolean;

    /**
    * This property is only valid for LIST_RECEIVED events, and it represents the user’s
    * entire buddy list.
    */
    public var buddyList:BuddyList;

    public function BuddyListEvent(type:String, buddy:User, group:Group, buddyList:BuddyList=null, bubbles:Boolean=false, cancelable:Boolean=false)
    {
    super(type, bubbles, cancelable);
    this.buddy = buddy;
    this.group = group;
    this.buddyList = buddyList;
    }

    override public function clone():Event
    {
    return new BuddyListEvent(type, buddy, group, buddyList, bubbles, cancelable);
    }

    override public function toString():String
    {
    var output:String = “[BuddyListEvent." + this.type +
    " buddy=" + buddy.toString() +
    ", group=" + group.toString() +
    ", buddyList" + buddyList.toString() +
    "]“;
    return output;
    }
    }
    }

  28. DJJaxe said,

    October 8, 2008 at 3:29 am

    also this is the string of code i get the error on:
    protected function onBLReceived(event:BuddyListEvent):void{
    currentState = ‘online’;
    buddiesList.dataProvider = event.buddyList.groups[0].users;
    buddiesList.labelFunction = blLF;
    }

  29. Bryan said,

    December 4, 2008 at 3:25 pm

    I keep getting this error when I try adding my btn code to my .as file:

    btn_1.addEventListener(MouseEvent.CLICK, btnClick1);

    function btnClick1(event:MouseEvent):void
    {var myLoader:Loader = new Loader();
    addChild(myLoader);
    myLoader.load(new URLRequest(“swf1.swf”));
    }

    Here is my .as file:
    package usababyvb
    {
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.events.*;
    import fl.controls.ComboBox;
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    import flash.net.URLRequest;
    import flash.net.navigateToURL;
    import caurina.transitions.Tweener;

    public class Main extends MovieClip
    {
    private var file_xml:LoadingXML;

    public var cat_names_array:Array=new Array();
    public var products_array:Array=new Array();

    private var id_cat:int=0;
    private var id_prod:int=0;

    private var product:Product;

    public function Main()
    {
    addEventListener(Event.ADDED_TO_STAGE,init);
    }

    private function init(evt:Event):void
    {
    stage.frameRate=31;

    initMenu();

    menu_mc.y=stage.stageHeight+30;
    menu_mc.prev_btn.label=’PREV’;
    menu_mc.next_btn.label=’NEXT’;
    menu_mc.prev_btn.useHandCursor=true;
    menu_mc.next_btn.useHandCursor=true;
    menu_mc.prev_btn.addEventListener(MouseEvent.MOUSE_DOWN,setPrev);
    menu_mc.next_btn.addEventListener(MouseEvent.MOUSE_DOWN,setNext);
    file_xml=new LoadingXML(this);
    }

    public function dataHasBeenStored():void
    {
    initCategories();
    displayProduct();
    resetButtonsVisible();
    }

    private function initCategories():void
    {
    for(var i:int=0;i<cat_names_array.length;i++)
    {
    cat_combo.addItem({label:cat_names_array[i],data:i.toString()});
    }
    cat_combo.addEventListener(Event.CHANGE,setItem);
    }

    private function setItem(evt:Event):void
    {
    id_cat=evt.target.selectedItem.data;
    id_prod=0;
    resetButtonsVisible();
    product.destroy();
    displayProduct();
    }

    private function displayProduct():void
    {
    menu_mc.info_txt.text=(id_prod+1)+’ / ‘+products_array[id_cat].length;
    product=new Product(cat_names_array[id_cat],products_array[id_cat][id_prod].name,products_array[id_cat][id_prod].thumb,
    products_array[id_cat][id_prod].price,products_array[id_cat][id_prod].image,products_array[id_cat][id_prod].des);
    product.x=stage.stageWidth/2;
    product.y=stage.stageHeight/2;
    addChild(product);
    }

    private function setPrev(evt:MouseEvent):void
    {
    id_prod–;
    menu_mc.info_txt.text=(id_prod+1)+’ / ‘+products_array[id_cat].length;
    if(id_prod=products_array[id_cat].length-1)
    {
    evt.target.visible=false;
    evt.target.parent.prev_btn.visible=true;
    id_prod=products_array[id_cat].length-1;
    }
    else
    evt.target.parent.prev_btn.visible=true;
    product.destroy();
    displayProduct();
    }

    public function resetButtonsVisible():void
    {
    Tweener.addTween(menu_mc,{y:stage.stageHeight+30,time:.3,transition:”linear”,onComplete:buttonsBack});
    function buttonsBack():void
    {
    Tweener.addTween(menu_mc,{y:447,time:.3,transition:”linear”});
    }
    menu_mc.prev_btn.visible=false;
    menu_mc.next_btn.visible=true;
    }

    public function resetButtonsVisibleFromProduct():void
    {
    Tweener.addTween(menu_mc,{y:stage.stageHeight+30,time:.3,transition:”linear”,onComplete:buttonsBack});
    function buttonsBack():void
    {
    Tweener.addTween(menu_mc,{y:385,time:.3,transition:”linear”});
    }
    }

    public function hideButtons():void
    {
    Tweener.addTween(menu_mc,{y:stage.stageHeight+30,time:.3,transition:”linear”});
    }

    private function initMenu():void
    {
    var etichetta:String=’Flash CS3 components’;
    var cm:ContextMenu=new ContextMenu();
    var item:ContextMenuItem=new ContextMenuItem(etichetta);
    cm.hideBuiltInItems();
    cm.customItems.push(item);
    item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,itemHandler1);
    this.contextMenu=cm;
    }
    private function itemHandler1(event:ContextMenuEvent):void
    {
    var url:String=’http://usababyvb.com/’;
    var request:URLRequest=new URLRequest(url);
    navigateToURL(request,’_parent’);

    }
    }
    }

  30. adam said,

    December 23, 2008 at 6:46 pm

    hey thanks!! yer first tip really helped me.

  31. JC said,

    December 24, 2008 at 1:42 pm

    Thanks for this, but I think you should have the second tip first :P

  32. sebas said,

    February 2, 2009 at 3:36 am

    The 1046 error will also pop up if you have a class file inside a (valid) classpath and (by accident due to sloppyness) a similar class file next to your .fla or somewhere else within your classpath.. Lesson: when moving a class file to a new location always make sure to delete the old one..

    Took me a couple of hours to tackle that one.. :-)

  33. Connie H. said,

    March 1, 2009 at 5:22 am

    Just wanted to say Thank You for the details on the 1046 error, it enabled me to figure out where I went wrong!

  34. Jason Lough said,

    April 2, 2009 at 4:33 pm

    “Tricky said,

    November 15, 2007 at 2:58 pm

    Don’t forget to make sure you’ve declared your class public ”

    WIN!! Saved me quite a bit of time there, ty much.

  35. Karina said,

    April 23, 2009 at 11:45 pm

    I wish this helped… but all i have in the my actionscript is stop();
    It worked once, and now it always gives me this error!!

    I wanna rip my hear out! What else could the error be? Stuff on the stage? in the library?

    Please help!!

  36. Wiki Bean said,

    April 29, 2009 at 6:50 am

    You can also get error 1046 when you use a method in a function (in a package) without first importing the class.

    Like when you put this:

    stage.addEventListener(MouseEvent.MOUSE_DOWN, nameFunction)

    in a function, and forgot to say

    import flash.events.*

  37. James said,

    May 7, 2009 at 2:48 am

    THANK YOU THANK YOU THANK YOU!
    The second tip helped me… and I did a little celebratory dance… cause that pretty much just made my day.

  38. facetus said,

    July 23, 2009 at 2:58 am

    Thank you so much for the Fix 1 of Error #1046!!!

  39. ex1 said,

    August 15, 2009 at 8:15 am

    package {
    import flash.display.MovieClip;
    import flash.events.Event;

    public class Engine extends MovieClip {

    private var RangeHUD:RangeHUD;

    public function Engine(): void {
    RangeHUD = new RangeHUD(stage);
    stage.addChild(RangeHUD);
    }
    }
    }

    I have the RangeHUD class.
    But im getting this:
    1046: Type was not found or was not a compile-time constant: RangeHUD.

  40. Shaun Bliss said,

    August 30, 2009 at 1:44 am

    I just got this error on a mx:BubbleChart not being found.

    In the end I tracked it down to the Flex SDK 3.3

    I changed it back to SDK 3.2 and everything works now. :-)

    Just in case anyone else had a similar problem …

    Not sure what’s up with 3.3 :-(

    Shaun

  41. Vero said,

    September 16, 2009 at 8:31 pm

    Thanks again!!! Excellent tips

  42. Re: Flash CS3 / Flex 2 AS3 Error #1046 | seventy6 said,

    November 2, 2009 at 9:52 am

    [...] http://curtismorley.com/2007/06/20/flash-cs3-flex-2-as3-error-1046/ Share and Enjoy: [...]

  43. Martijn said,

    December 22, 2009 at 3:20 am

    Hey There,

    I have also the 1046 error. But I don’t know how to fix this. I am working on a augmented reality project and I am working with flex builder 3. I have only one .as file with my code and that’s it. I don’t have a flash file with object in it so I have no idea where to look. The error is based on this line:

    private function loop(e:Event):void I have also a line with this code: addEventListener(Event.ENTER_FRAME, loop); and I think it has something to do with each other. What do I miss???

    Thanksss

  44. Jacob said,

    January 6, 2010 at 3:33 pm

    I get this error whenever i try to use a timer

    Heres my code:

    package{
    import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
    public class Main extends MovieClip{
    public var obj:String;
    public var mytimer:Timer;
    public function Main(){
    ShowButtons();
    _Back.addEventListener(MouseEvent.CLICK, BackClick);
    _Collar.addEventListener(MouseEvent.CLICK, CollarClick);
    _Office.addEventListener(MouseEvent.CLICK, OfficeClick);
    }
    public function ChangeBG(obj:String):void{
    _Change_BG._BG.gotoAndStop(obj);
    _Change_BG.play();
    }
    public function ShowButtons():void{
    _Collar.gotoAndPlay(2);
    _Office.gotoAndPlay(2);
    }
    public function HideButtons():void{
    _Collar.gotoAndPlay(17);
    _Office.gotoAndPlay(17);
    }
    public function BackClick(event:MouseEvent):void{
    _Change_BG.play();
    ShowButtons();
    }
    public function CollarClick(event:MouseEvent):void{
    HideButtons();
    _Collar._Collar_Inner.gotoAndStop(31);
    _Collar._Collar_Inner_2.gotoAndStop(31);
    ChangeBG(“Collar”);
    }
    public function OfficeClick(event:MouseEvent):void{
    HideButtons();
    _Office._Office_Inner.gotoAndStop(31);
    _Office._Office_Inner_2.gotoAndStop(31);
    ChangeBG(“Office”);
    }
    }
    }

  45. Alex said,

    January 16, 2010 at 10:52 pm

    Hi, I’m relatively new to actionscript, and I’ve been getting this error when linking my .as file to my .fla. I’m using this tutorial.
    http://asgamer.com/2009/as3-character-movement-helicopter-games/comment-page-1#comment-4542

    I changed it around a bit because I wanted it to be like a straight shooter and not like a helicopter, but that’s pretty much just the physics, not the linking.

    Upon compiling, the fla throws the 1046 error for the line Helicopter(stageRef:Stage):void{
    and says “Type was not found or was a compile-time constant: Stage”

    At first I thought that it was because I had named the instance name for my ship “Ship”, same as my class in the .as file, but after changing the class name the error persisted.

    The thing I find puzzling is the stageRef variable. It seems to work, but can’t be accessed in the Helicopter function…

    Maybe I’m just doing something stupid?

  46. Parasar said,

    June 16, 2010 at 1:12 am

    Thanks a lot Curtis…
    had a problem with with my site that im building

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at About$iinit()

    was solved my method FIX 2..importing a class and initializing it with the code

    public function About() // this function ensures that when the website is added to stage the Website() class is called
    {
    this.addEventListener(Event.ADDED_TO_STAGE, init);
    }

    public function init(e:Event):void
    {
    …..
    }

  47. Ole said,

    July 27, 2010 at 8:39 am

    I got rid of this error 1046 caused by the code below by simply removing the void statement. I can’t say why it works, but it does…

    function packagedF():void{
    checkSec.removeEventListener(TimerEvent.TIMER, checkerF);
    rawImage = imgData.image[imgNum].imgURL;
    numberOfChildren = imgData.*.length();
    rawW = imgData.image[imgNum].imgW;
    rawH = imgData.image[imgNum].imgH;
    title_txt.text = imgData.image[imgNum].imgTitle;
    imageLoader = new Loader;
    imageLoader.load(new URLRequest(rawImage));
    master_mc.addChild(imageLoader);
    imageLoader.x = (stage.stageWidth – Number(rawW)) /2;
    imageLoader.y = (stage.stageHeight -50 – Number(rawH)) /2;
    }

  48. Jethro said,

    August 23, 2010 at 1:15 pm

    This also happened to me, but because I had a Function with the same name as the LinkageID.
    Thanks Curtis, each article on here is spot on and perfectly clear and explained :)

  49. quiet0ne said,

    October 24, 2010 at 4:28 pm

    This single post fixed a problem I had been wrestling with for two hours. Just wanted to say thank you!!!

  50. Blitz said,

    January 2, 2011 at 12:06 pm

    thanks mate your blog really does save me from hammering my head to wall..,
    this time because i forgot to import the textfield dor textfield inside my movieclip.

    keep up the good work mate.

  51. Ptericles said,

    April 9, 2011 at 6:33 pm

    Problem: Getting a 1046 error (Type was not found or was not a compile-time constant: PieChart.)

    Possible soln:

    Inside of the src folder, you have to put all required classes in there. for exmaple, if my PieChart class is in lib.charts, I would have to put the lib folder inside of src. Then you can use the statement to import the class:

    import lib.charts.PieChart;

  52. Anne said,

    April 24, 2011 at 7:28 am

    I have been stressing over this error for two days. Your definition/explanation is the best I’ve seen and gives me hope. Thanks!

  53. Curtis J. Morley said,

    April 29, 2011 at 10:03 am

    Thanks for the comment Anne. AS3 Error #1046 can be a tricky Flash Error. Glad this helped.

  54. Joel said,

    May 13, 2011 at 11:04 am

    Thanks for the post! I did not import the TweenEvent class, and that fixed my issue! I really appreciate you posting this!

  55. Snezana said,

    July 27, 2012 at 8:38 am

    thank you, thank you , thank you!!!!!!!!!!!!

  56. A Tutorial in AS3 with Flashdevelop | Precision Code said,

    January 6, 2013 at 3:37 pm

    [...] Using our earlier example I paste: Error: Type was not found or was not a compile-time constant into google along with AS3 so that I get answers for ActionScript 3. http://curtismorley.com/2007/06/20/flash-cs3-flex-2-as3-error-1046/ [...]

Leave a Comment