06.20.07
Flash CS3 / Flex 2 AS3 Error #1046
Error #1046: Type was not found or was not a compile-time constant: defsTab_mc.
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.
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'.
And now you know two ways to resolve ActionScript Error #1046: Type was not found or was not a compile-time constant:
As always Happy Flashing!
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
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.
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
{}
}
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
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
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.
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 {
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.
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
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.
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
Carroll Altman said,
February 8, 2008 at 7:17 pm
I left a comment here yesterday with a question. Where did it go?
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
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
Aral Balkan said,
April 16, 2008 at 3:08 am
LOL, or “package _signature_” even! (’nuff said!)
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?
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.
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
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 !
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
curtismorley.com » Search Engine Optimization Example said,
June 2, 2008 at 4:42 pm
[...] ActionScript 3 Error - #2 on Google [...]
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 [...]
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.
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;
}
}
}
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 [...]
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
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
BuddyListEventis 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;
}
}
}
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;
}
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’);
}
}
}
adam said,
December 23, 2008 at 6:46 pm
hey thanks!! yer first tip really helped me.
JC said,
December 24, 2008 at 1:42 pm
Thanks for this, but I think you should have the second tip first
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..
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!
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.
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!!
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.*
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.