本文介绍了AS3 - 从资产类越来越库符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个Assets.swf中,在其中我想继续我的所有符号。然后,我创建了由它来完成嵌入的资产类。它看起来是这样的:
I have created an assets.swf, in which I want to keep all my symbols. Then, I have created an Assets class which does the embedding. It looks like this:
public class Assets extends MovieClip
{
[Embed(source="assets.swf", symbol="MyBox")]
public static var MyBox:Class;
public function Assets()
{
}
}
现在,在其它的类,我想创建一个新的盒子:
Now, in some other class, I want to create a new box:
import com.company.Assets;
...
public function Game()
{
var myBox:MovieClip = new Assets.MyBox();
addChild(myBox);
}
我知道这不正确的,我也得到类型错误:错误#1007:实例化尝试对非构造函数。我怎样才能获得资产在资产类?
I know this in incorrect, and I get "TypeError: Error #1007: Instantiation attempted on a non-constructor." How can I get access to the assets in the Assets class?
推荐答案
编辑:我想你会找到答案的。
I think you will find the answer here.
以下适用于使用的类加载装载机
类。
The following applies to using classes from an SWF loaded with Loader
class.
private function onLoad(e:Event):void
{
var domain:ApplicationDomain = LoaderInfo(e.target).applicationDomain;
var Type:Class = domain.getDefinition("pack.MyComponent") as Class;
var myBox:MovieClip = new Type();
addChild(myBox);
}
这篇关于AS3 - 从资产类越来越库符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!