我已经阅读了所有类似的主题,但没有运气,所以我发布了一个关于这个错误的新问题。
我正在尝试使用以下代码从另一个swf文件加载swf文件:
var loader:Loader = new Loader()
//listen for loading progress
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
//listen for when the load is finished
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onLoaderError);
//load!
var rr:URLRequest = new URLRequest("http://localhost/Gen-Tree.swf")
loader.load(rr);
function onLoaderError(event:SecurityErrorEvent) {
trace("hi")
}
function onProgress(event:ProgressEvent):void
{
//calculate how much has been loaded
var percentageLoader:Number = event.bytesLoaded / event.bytesTotal;
//use your percentage number here to drive a loader bar graphic
}
function onComplete(event:Event):void
{
//remove listeners now that loading is done
loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgress);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
//add loaded swf to the stage
addChild(loader.content);
}我得到了如下的错误消息:
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'
*** Security Sandbox Violation ***
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'
*** Security Sandbox Violation ***
SecurityDomain 'http://localhost/Gen-Tree.swf' tried to access incompatible context 'file:///C|/Users/Alex/Desktop/Gen%2DTree%202012/Programming/loader.swf'有什么想法吗?
发布于 2012-07-12 05:25:21
您正在尝试从文件系统加载外部swf,这将抛出安全错误。把它放在服务器上,只要两个swfs在同一个域上,它就应该工作得很好。或者运行本地服务器并在该服务器上试用。
如果这两个crossdomain.xml不在同一个域中,则需要添加一个swfs。它将位于服务器根目录下,如下所示:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>除非你不应该仅仅使用*,因为它会给你带来安全风险。您需要明确地将另一个域列入白名单。您可以了解有关跨域策略文件here的更多信息。
更新:
此外,由于加载器swf正在访问它正在加载的内容(通过loader.content),您将需要为该内容swf添加安全权限(看起来它被称为Gen-Tress.swf):
import flash.system.Security;
Security.allowDomain("*");同样值得注意的是,Loader是一个DisplayObject,这意味着您可以使用addChild(loader)而不是addChild(loader.content)将其直接添加到stage中。通过不访问Loader的内容,您通常可以避免安全沙箱冲突错误,并且不必处理允许域和跨域策略。
发布于 2012-07-12 06:27:41
您可以尝试加载swf,然后使用loader.loadBytes()重新加载加载器内容。这样,您就可以创建swf的字节数组克隆,并绕过安全沙箱。到目前为止,它在图像上工作得很好。我在我的博客上解释了这个过程:http://www.inklink.co.at/blog/?p=14
下面是一个包含图像的示例:
function loadPicture():void
{
var req:URLRequest = new URLRequest("YOUR_URL_HERE");
var _picLoader:Loader = new Loader();
_picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,loader2ByteArray);
_picLoader.load(req);
}
function loader2ByteArray(evt:Event):void
{
var lInfo:LoaderInfo = LoaderInfo(evt.target);
var ba:ByteArray = lInfo.bytes;
reloadByteArray(ba);
}
function reloadByteArray(ba:ByteArray):void
{
var reloader:Loader = new Loader();
reloader.loadBytes(ba);
reloader.contentLoaderInfo.addEventListener(Event.COMPLETE, reloaderComplete);
}
function reloaderComplete(evt:Event):void
{
var imageInfo:LoaderInfo = LoaderInfo(evt.target);
var bmd:BitmapData = new BitmapData(imageInfo.width,imageInfo.height);
bmd.draw(imageInfo.loader);
var resultBitmap:Bitmap = new Bitmap(bmd);
addChild(resultBitmap);
}希望它能帮上忙!
发布于 2012-08-23 15:40:14
var loader_context:LoaderContext = new LoaderContext();
if (Security.sandboxType!='localTrusted') loader_context.securityDomain = SecurityDomain.currentDomain;
loader_context.applicationDomain = ApplicationDomain.currentDomain;
currentLoader = new Loader();
currentLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
currentLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
currentLoader.load(new URLRequest(baseLink + pName + ".swf"), loader_context);也许您可以尝试将loadercontext添加到其中。
https://stackoverflow.com/questions/11441645
复制相似问题