热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

是什么导致Flash错误#2012(无法实例化类)?-WhatCausesFlashError#2012(Can'tinstantiateclass)?

IamnewtoActionScript3andhaverunintoaproblem:我是ActionScript3的新手,遇到了一个问题:UsingFlexBui

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

我是ActionScript 3的新手,遇到了一个问题:

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:

使用Flex Builder 3,我创建了一个包含几个简单类的项目。如果类A中的代码实例化了类B的对象(类B在它自己的源文件中),那么代码编译得很好,但是我得到以下运行时错误:

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

ArgumentError:错误#2012:B类无法实例化。

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).

更新:请在下面看到我自己的答案(由于我还没有注册,我无法将其投票到顶部)。

3 个解决方案

#1


21  

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.

我终于意识到错误了:B类是DisplayObject的子类,我现在看到它是一个抽象类。 B类没有实现抽象成员,因而错误。我可能会将B类更改为Sprite的子类。

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.

感谢大家的答案,希望他们能帮助其他遇到错误的人2012。

#2


2  

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

这通常意味着类信息未包含在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).

确保您正在导入该类,并且某处有一个对它的引用(因此编译器会将它包含在SWF中)。

btw, here are the runtime error codes:

顺便说一句,这是运行时错误代码:

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

(not much useful info though)

(虽然没有太多有用的信息)

mike chambers

mesh@adobe.com

#3


0  

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:

值得注意的是,如果您包含其他人构建的类,并且他们使用Flash CS3并且您正在使用Flex,反之亦然,那么每个类的核心库都是不同的,并且两者中都没有包含某些内容。查看两个参考文档以确定:

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

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


推荐阅读
author-avatar
墨镜小靖
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有