我正在做一些简单的代码。我有一个要扩展的类插件,函数initialise():
package me.bleachisback.cocmod {
import me.bleachisback.cocmod.CoCMain;
public class Plugin {
private var _main:CoCMain;
private var _name:String;
private var _desc:String;
private var _ver:String;
private var _auth:String;
internal var _enabled:Boolean = false;
internal function initialise(main:CoCMain, name:String, description:String, version:String, author:String):void {
_main = main;
_name = name;
_desc = description;
_ver = version;
_auth = author;
}
}
}
我的主要类加载插件,然后初始化它们:
package me.bleachisback.cocmod {
import me.bleachisback.cocmod.Plugin;
public class CoCMain extends MovieClip {
private function pluginLoadingComplete(e:Event):void {
//This class extends Plugin
var plugin:Object = new e.target.content.mainClass();
var desc:XML = new XML(e.target.content.description);
trace(this); //outputs: [object CoCMain]
plugin.initialise(this, desc.name[0], desc.description[0], desc.version[0], desc.author[0]);
}
}
}
但最后,当我尝试使用初始化函数时,它给了我这个错误:
TypeError: Error #1034: Type Coercion failed: cannot convert me.bleachisback.cocmod::CoCMain@4dfc041 to me.bleachisback.cocmod.CoCMain.
at me.bleachisback.cocmod::CoCMain/pluginLoadingComplete()
暗示我无法将类转换为自身???
答案 0 :(得分:0)
加载外部SWF时,可以指定将加载类定义的applicationDomain。默认情况下,外部加载的SWF会将其类定义放在新的应用程序域中,因此在原始应用程序域中不会替换同名的类。
尝试将SWF加载到当前应用程序域中,如下所示:
var ldrContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
创建LoaderContext时请注意 ApplicationDomain.currentDomain 。
您可以在此处查看示例: http://help.adobe.com/en_US/as3/dev/WSd75bf4610ec9e22f43855da312214da1d8f-8000.html