从另一个沙箱中的内容加载外部类
问题是:我有(例如)字体嵌入器类,并且我想加载外部 SWF,而不是从应用程序存储文件夹,而是从 AIR 中的另一个本地路径(“D:\blah-blah\123.swf”)加载,但作为你知道我在互联网上找不到任何决定(Google,Adode.com)
Security.allowDomain() not working in AIR ( documented on adobe.com)
Trick with ApplicationDomain is not working ( same documented on adobe.com)
我想要的只是从加载的内容中获取CLASS REFERENCE并在加载启动器中使用。
有人知道如何解决这个问题吗?
列出用于熟悉的代码:
_
_
[主 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];
}
The problem is: I have (for example) font embeder class, and I want to load external SWF not from application storage folder, but another local path ( "D:\blah-blah\123.swf") in AIR, but as you understand I can't find any decision on the Internet (Google, Adode.com)
Security.allowDomain() not working in AIR ( documented on adobe.com)
Trick with ApplicationDomain is not working ( same documented on adobe.com)
The all I want, is to get CLASS REFERENCE from loaded content and use in load initiator.
Does anybody knows how to solve this problem?
listing code for getting acquaint:
_
_
[main AIR-app code sheet]
// 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));
}
_
_
[external SWF code]
function _getRef() : Array
{
// class1,2,3 are font classes imported in library
return [ class1, class2, class3];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚设法让我的代码正常工作。
因此,如果其他人遇到同样的问题,我必须执行以下操作:
使用 FileStream 读取 swf 文件
stream.readBytes(bytes)
创建一个新的 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()加载策略文件
我使用的swf文件是使用Flash CS3创建的,通过将新的字体实例添加到库中。我没有运气使用 [Embed] 创建它们,因为生成的类存储为 TrebuchetMS_TrebuchetMS,而不是实际的类名称 TrebuchetMS。
我不必创建安全桥 (LoaderInfo.childSandboxBridge)
我希望我没有忘记任何事情。
I just managed to get my code working.
So here's everything I had to do in case someone else has the same issue:
Read the swf file using a FileStream
stream.readBytes(bytes)
Create a new Loader object and load the bytes on that, using a 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);
Make sure you do NOT call Security.allowDomain() inside the loaded swf. It doesn't work with AIR, as @Focker mentions.
There is no need to load a policy file with Security.loadPolicyFile()
The swf files I used were created using Flash CS3, by adding new Font instances to the Library. I had no luck creating them with [Embed], as the resulting class was stored as TrebuchetMS_TrebuchetMS for example, instead of the actual class name which was TrebuchetMS.
I didn't have to create a security bridge (LoaderInfo.childSandboxBridge)
I hope I'm not forgetting anything.