views:

2371

answers:

5

I am new to ActionScript 3 and have run into a problem:

Using Flex Builder 3, I have a created a project with a few simple classes. If code in class A instantiates an object of class B (class B is in its own source file) then the code compiles fine, but I get the following run time error:

ArgumentError: Error #2012: B class cannot be instantiated.

Can someone explain what I'm doing wrong?

Update: Please see my own answer below (I could not vote it to the top since I'm not yet registered).

+1  A: 

This usually means that the class information was not included in the SWF.

Make sure that you are importing the class, and that there is a reference to it somewhere (so the compiler will included it in the SWF).

btw, here are the runtime error codes:

http://livedocs.adobe.com/flex/201/langref/runtimeErrors.html

(not much useful info though)

mike chambers

[email protected]

mikechambers
A: 

It's worth noting that if you're including classes that someone else built, and they used Flash CS3 and you're using Flex, or vice versa, that the core libraries of each are different and some things are not included in both. Check out the two reference docs to be sure:

CS3: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/

Flex: http://livedocs.adobe.com/flex/2/langref/

UltimateBrent
+8  A: 

I finally realized what was wrong: Class B was subclassing from DisplayObject which I now see is an abstract class. Class B did not implement the abstract members, thus the error. I'll probably change class B to subclass from Sprite instead.

This seems like a problem that should have been caught by the compiler. Does the fact that it wasn't mean implementation of abstract members can wait until run time? Even if so, it would be nice to at least get a compiler warning.

Thanks for everyone's answers, hopefully they will help others who run into error 2012.

A: 

10x on the help on that, i had the same problem with the abstract class.

A: 

Hi! Thanks UltimateBrent that was the exact problem I have, I'm using some classes written in Flash CS3 and I'm using Flex :S Now I have to find the differences

tati