Flash - 无法访问另一个 SWF 中的类
我正在尝试加载本地 SWF 文件并使用该 SWF 中的类(它只是代码 SWF,库中没有任何内容)。
下面是加载库的代码:
var AD:ApplicationDomain = ApplicationDomain.currentDomain;
var context:LoaderContext = new LoaderContext(false, AD);
SA_gamecore_loader = new Loader();
SA_gamecore_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameCoreLibraryDataComplete);
SA_gamecore_loader.load(new URLRequest("GameCore.swf"), context);
这是尝试从 GameCore.swf 实例化类的代码:
var test:Class = GetClassFromDefinition("MenuArt") as Class;
var testInstance:Object = new test();
public function GetClassFromDefinition(theStr:String):Object
{
var theClass:Object;
try
{
theClass = GameCoreLibraryData.applicationDomain.getDefinition(theStr);
}
catch(e:ReferenceError)
{
trace(e);
return null;
}
return theClass;
}
这是跟踪的消息:
ReferenceError: Error #1065: Variable MenuArt 未定义。
GameCore.swf 与父 swf 位于同一位置。我正在使用 Flash Develop,如果有帮助的话。有人能指出我做错了什么吗?
I'm trying to load a local SWF file and use the classes in that SWF (its a code only SWF, nothing in library).
Here's the code that loads the library:
var AD:ApplicationDomain = ApplicationDomain.currentDomain;
var context:LoaderContext = new LoaderContext(false, AD);
SA_gamecore_loader = new Loader();
SA_gamecore_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onGameCoreLibraryDataComplete);
SA_gamecore_loader.load(new URLRequest("GameCore.swf"), context);
Here's the code that tries to instantiate a class from GameCore.swf:
var test:Class = GetClassFromDefinition("MenuArt") as Class;
var testInstance:Object = new test();
public function GetClassFromDefinition(theStr:String):Object
{
var theClass:Object;
try
{
theClass = GameCoreLibraryData.applicationDomain.getDefinition(theStr);
}
catch(e:ReferenceError)
{
trace(e);
return null;
}
return theClass;
}
And this is the message that's traced:
ReferenceError: Error #1065: Variable MenuArt is not defined.
The GameCore.swf is in the same location as the parent swf. I'm using Flash Develop if that helps. Anyone able to point out what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于找到问题所在了。我必须在 getDefinition 调用中包含包名称。所以就我而言:
Finally figured out the problem. I had to include the package name in the getDefinition call. So in my case: