从另一个沙箱中的内容加载外部类
问题是:我有(例如)字体嵌入类,并且我想从应用程序存储文件夹中加载外部SWF,但不是另一个本地路径(“D:\ blah-blah \ 123.swf“)在空气中,但你知道我不能在互联网上找到(谷歌,Adode.com)从另一个沙箱中的内容加载外部类
Security.allowDomain() not working in AIR (documented on adobe.com)
Trick with ApplicationDomain is not working (same documented on adobe.com)
任何决定我要的,是获得类参考从加载内容并在加载启动器中使用。
有谁知道如何解决这个问题?
_
_
[主AIR-应用代码片]
// function and one param (path to content)
function tralala(_swfPath : String)
{
var l : Loader = new Loader();
l.contentLoaderInfo.
addEventListener(Event.COMPLETE,
function(_e : Event)
{
var tmp = _e.target.content;
// call function from SWF and retrieving
// classes, but can't work with them
Font.registerFont(tmp._getRef()[0]);
// no error checking for clarity
}
);
l.load(new URLRequest(_swfPath));
}
_
_
:用于获取初识列表代码
[外部SWF代码]
function _getRef() : Array
{
// class1,2,3 are font classes imported in library
return [ class1, class2, class3];
}
我只是设法让我的代码工作。
因此,这里的一切,我在的情况下别人做了同样的问题:
-
使用一个FileStream
stream.readBytes(字节)读取SWF文件
-
创建一个新的Loader对象并使用LoaderContext加载该字节,var loader:Loader = new Loader(); loadercontentLoaderInfo.addEventListener(Event.COMPLETE,fontFileLoaded,false,0,true);
var context:LoaderContext = new LoaderContext(); context.applicationDomain = ApplicationDomain.currentDomain; context.allowCodeImport = true;
loader.loadBytes(bytes,context);
确保您不会在加载的swf中调用Security.allowDomain()。正如@Focker所说,它不适用于AIR。
无需加载使用Security.loadPolicyFile()策略文件
我曾经使用Flash CS3,通过添加新字体实例库中创建的SWF文件。我没有用[Embed]创建它们,因为结果类被存储为TrebuchetMS_TrebuchetMS,而不是实际的类名TrebuchetMS。
我不必创建安全桥(LoaderInfo。childSandboxBridge)
我希望我不会忘记任何事情。
Thx回复。希望它能帮助别人。 – Focker 2011-07-28 20:51:29